简体   繁体   English

来自网络服务的响应:方法不允许

[英]Response from webservice : method not allowed

I have a .net web service with the following OperationContract: 我有一个带有以下OperationContract的.net Web服务:

    [OperationContract]
    [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "testing2?coName={coName}&password={password}")] 
    string testing2(string coName, string password);   

when trying to access it from my local host: 尝试从本地主机访问它时:

http://.../service1.svc/testing2?coName=abcd&password=1234qw

(... is my local host) (...是我的本地主机)

I get the following response in my browser: 我在浏览器中收到以下响应:

Service 服务

Method not allowed. 不允许的方法。

If you want to invoke a method that expects type POST, you should POST it, or else it won't register correctly. 如果要调用需要POST类型的方法,则应该对其进行POST,否则它将无法正确注册。 If you're invoking such method by visiting its URL, it will deny the access (that's GET method, that's why it worked previously). 如果您通过访问其URL来调用这种方法,它将拒绝访问(这是GET方法,这就是以前使用的原因)。 If you're not actually posting some data in the body, switch back to GET if you want to invoke it by using an URL. 如果您实际上没有在正文中发布某些数据,则如果要使用URL调用它,请切换回GET。

Try enable anonymous access on this webservice 尝试在此Web服务上启用匿名访问

<security>
 <authentication>
  <anonymousAuthentication enabled="true" />
 </authentication>
</security>

Method not allowed has error code HTTP error code 405. The Possible reason you are getting is because of missing Request property Accept. 不允许的方法具有错误代码HTTP错误代码405。可能的原因是由于缺少请求属性“接受”。 I really don't want to give you an incorrect code, because I don't know wcf, but this is what you can do once you set a connection, 我真的不想给您一个不正确的代码,因为我不知道wcf,但这是您设置连接后可以执行的操作,

connection.setRequestProperty("Accept", "*/*");

You need to find similar method that can achieve this task in wcf. 您需要找到可以在wcf中完成此任务的类似方法。

Read this page for more information. 阅读此页面以获取更多信息。

The other reason is if that particular method POST is not allowed on the webservice end, that's when you will get method not allowed. 另一个原因是,如果特定的方法POST在Web服务端不被允许,那就是您将获得不允许的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM