WCF 服务返回“不允许的方法" [英] WCF Service Returning "Method Not Allowed"
本文介绍了WCF 服务返回“不允许的方法"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在开发我的第一个 WCF 服务的过程中,当我尝试使用它时,我得到Method not Allowed",没有其他解释.
In the process of developing my first WCF service and when I try to use it I get "Method not Allowed" with no other explanation.
我已经使用 ServiceContract 和 OperationContract 设置了我的接口:
I've got my interface set up with the ServiceContract and OperationContract:
[OperationContract]
void FileUpload(UploadedFile file);
连同实际方法:
public void FileUpload(UploadedFile file) {};
要访问服务,我输入 http://localhost/project/myService.svc/FileUpload但我收到不允许的方法"错误
To access the Service I enter http://localhost/project/myService.svc/FileUpload but I get the "Method not Allowed" error
我错过了什么吗?
推荐答案
您的浏览器正在发送 HTTP GET 请求:确保您在合同中的操作上具有 WebGet 属性:
Your browser is sending an HTTP GET request: Make sure you have the WebGet attribute on the operation in the contract:
[ServiceContract]
public interface IUploadService
{
[WebGet()]
[OperationContract]
string TestGetMethod(); // This method takes no arguments, returns a string. Perfect for testing quickly with a browser.
[OperationContract]
void UploadFile(UploadedFile file); // This probably involves an HTTP POST request. Not so easy for a quick browser test.
}
这篇关于WCF 服务返回“不允许的方法"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文