通过HTTP发布到WCF服务

时间:2011-03-25 10:50:15

标签: wcf http post

我无法通过HTTP Post将数据发布到WCF服务,并将重定向响应发送回用户。

我的服务如下:

[ServiceContract]
public interface IXXLeadServiceWCF
{
 [WebInvoke(UriTemplate = "invoke")]
 [OperationContract]
 void CreateCallBack(Stream input);
}

操作合同接受Web调用如下:

[OperationBehavior]
public void CreateCallBack(Stream input)
{
 StreamReader sr = new StreamReader(input); 
 string s = sr.ReadToEnd(); 
 sr.Dispose(); 
 NameValueCollection qs = HttpUtility.ParseQueryString(s); 
 string firstName = qs["firstName"];

WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Redirect;
WebOperationContext.Current.OutgoingResponse.Location = "http://www.test.com";
}

我正在发布这样的服务:

<form method="post" action="http://wcf.xxx.com/LeadService/LeadService.svc">
 <input name="firstName" id="firstName" class="txt_input" type="text" value="" />
</form>

我只从帖子中找到一个空白页面。在WCF中对来自其他域的HTTP发布是否有限制?

如果有人能指出我正确的方向,我真的很感激。

由于

尼克

1 个答案:

答案 0 :(得分:0)

相信你的HTML表单需要编码multipart / form-data,是吗?另外,你的WebInvoke需要一种POST方法,对吧? UriTemplate定义方法将响应的URL以及它作为参数接受的值。

编辑:WebInvoke(方法=“POST”)