我正在尝试使用一个简单的WCF服务来处理来自REST HTTP POST的传入数据流,我之前创建了WCF Soap Webservices没有问题,但遇到了此POST操作的问题。我正在尝试创建一个接受传入POST的WCF Web服务。
我在Visual Studio中生成一个新的WCF项目,当我使用WCF测试客户端测试所做的默认项目时,它可以正常工作。但是,当我执行以下操作来尝试创建一个接受POST的WCF时,我让它正确构建,我让它正确启动而没有错误,它说服务已添加,并且它正确地生成了一个WSDL,但是当我试图发布它没有任何反应。在WCF测试客户端中,post操作有一个红色x,并说“Wcf Test Client不支持此操作,因为它使用类型System.IO.Stream”
该项目名为WcfService1。
IService1.cs文件具有服务合同:
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(UriTemplate="post")]
string post(Stream input);
}
文件Service1.svc.cs具有方法定义:
public string post(Stream input)
{
StreamReader sr = new StreamReader(input);
String postdata = sr.ReadToEnd();
sr.Dispose();
// simple debug statement
return "test";
}
我使用以下html来发布帖子:
<form method="post" action="http://localhost:49163/Service1.svc/post">
Test Data: <input type="text" name="TestField" />
<input type="submit" name="submit" value="Submit" />
</form>
我在http://blogs.southworks.net/erossetto/2007/09/03/raw-http-post-with-wcf/找到了一个例子,但我仍然遇到问题。我认为让这个工作变得非常简单。
答案 0 :(得分:1)
将绑定方法更新为webHttpBinding,如下例
<services>
<service name="SampleService" behaviorConfiguration="WebBehavior">
<endpoint address=""
behaviorConfiguration="WebBehavior"
binding="webHttpBinding"
bindingConfiguration=""
contract="ISampleService" />
</service>