我需要接受表单数据到基于WCF的服务.这是界面:
[OperationContract]
[WebInvoke(UriTemplate = "lead/inff",
BodyStyle = WebMessageBodyStyle.WrappedRequest)]
int Inff(Stream input);
Run Code Online (Sandbox Code Playgroud)
这是实现(示例 - 没有错误处理和其他安全措施):
public int Inff(Stream input)
{
StreamReader sr = new StreamReader(input);
string s = sr.ReadToEnd();
sr.Dispose();
NameValueCollection qs = HttpUtility.ParseQueryString(s);
Debug.WriteLine(qs["field1"]);
Debug.WriteLine(qs["field2"]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
假设WCF,除了解析传入流之外,还有更好的方法来实现吗?