C# 调用Web服务时如何解决HTTP状态405“Method Not Allowed”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/151413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to solve HTTP status 405 "Method Not Allowed" when calling Web Services
提问by Muxa
I've got a siluation where i need to access a SOAP web service with WSE 2.0 security. I've got all the generated c# proxies (which are derived from Microsoft.Web.Services2.WebServicesClientProtocol), i'm applying the certificate but when i call a method i get an error:
我有一个问题,我需要访问具有 WSE 2.0 安全性的 SOAP Web 服务。我已经获得了所有生成的 c# 代理(源自 Microsoft.Web.Services2.WebServicesClientProtocol),我正在应用证书,但是当我调用一个方法时出现错误:
System.Net.WebException : The request failed with HTTP status 405: Method Not Allowed.
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
I've done some googling and it appears that this is a server configuration issue. However this web service is used many clients without any problem (the web service is provided by a Telecom New Zealand, so it's bound to be configured correctly. I believe it's written in Java)
我已经做了一些谷歌搜索,这似乎是一个服务器配置问题。但是这个web服务被很多客户端使用都没有任何问题(web服务是由新西兰电信提供的,所以它一定要正确配置。我相信它是用Java编写的)
Can anyone shed some light on this issue?
任何人都可以对这个问题有所了解吗?
采纳答案by Muxa
Ok, found what the problem was. I was trying to call a .wsdl url instead of .asmx url. Doh!
好的,找到问题所在了。我试图调用 .wsdl url 而不是 .asmx url。哦!
回答by cruizer
hmm are those other clients also using C#/.NET?
嗯,那些其他客户端也在使用 C#/.NET 吗?
Method not allowed --> could this be a REST service, instead of a SOAP web service?
方法不允许 --> 这可能是 REST 服务,而不是 SOAP Web 服务吗?
回答by Juan Calero
I had the same problem, but the details were different:
我有同样的问题,但细节不同:
The Url we were using didn't have the file (.asmx) part. Calling the Url in a browser was OK. It also worked in a simple client setting the URL through Visual Studio. But it didn't worked setting the Url dynamically! It gave the same 405 error.
我们使用的 Url 没有文件 (.asmx) 部分。在浏览器中调用 Url 是可以的。它也适用于通过 Visual Studio 设置 URL 的简单客户端。但它没有工作动态设置 Url!它给出了相同的 405 错误。
Finally we found that adding the file part to the Web Service Url solved the problem. Maybe a .Net framework bug?
最后我们发现将文件部分添加到Web Service Url 解决了问题。也许是 .Net 框架错误?
回答by A-Dubb
I found this was due to WCF not being installed on IIS. The main thing is that the .svc extension has to be mapped in IIS See MSDN here.Use the ServiceModelReg tool to complete the installation. You'll always want to verify that WCF is installed and .svc is mapped in IIS anytime you get a new machine or reinstall IIS.
我发现这是由于 IIS 上没有安装 WCF。最重要的是 .svc 扩展名必须在 IIS 中映射,请参阅 MSDN 此处。使用 ServiceModelReg 工具完成安装。每当您获得新机器或重新安装 IIS 时,您总是希望验证 WCF 是否已安装,并且 .svc 是否已映射到 IIS 中。
回答by user1551704
MethodNotAllowedEquivalent to HTTP status 405. MethodNotAllowed indicates that the request method (POST or GET) is not allowed on the requested resource.
MethodNotAllowed等效于 HTTP 状态 405。MethodNotAllowed 指示请求方法(POST 或 GET)在请求的资源上不被允许。
The problem is in your enpoint uri is not full or correct addres to wcf - .scv Check your proxy.enpoint or wcf client.enpoint uri is correct.
问题在于您的 enpoint uri 不完整或 wcf 的正确地址 - .scv 检查您的 proxy.enpoint 或 wcf client.enpoint uri 是否正确。
回答by StanislavT.
In my case the problem was that the app config was incorrectly formed/called: in config the service url was using "localhost" as domain name, but real hostname differed from the URL I called :( so I changed the "localhost" in config to domainname thah I use in URL. That`s all!
在我的情况下,问题是应用程序配置的格式/调用不正确:在配置中,服务 url 使用“localhost”作为域名,但实际主机名与我调用的 URL 不同 :( 所以我在配置中更改了“localhost”到我在 URL 中使用的域名。仅此而已!
回答by Diego Elizondo
You needto enable HTTP Activation
您需要启用 HTTP 激活
Go to Control Panel > Windows Features > .NET Framework 4.5 Advanced Services > WCF Services > HTTP Activation
转到控制面板 > Windows 功能 > .NET Framework 4.5 高级服务 > WCF 服务 > HTTP 激活