【发布时间】:2014-10-13 07:07:08
【问题描述】:
我想读取 WCF Web 服务接收到的 HttpRequest 的正文。
WCF Web 服务如下所示:
[ServiceContract]
public interface ITestRestService
{
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/test")]
string Test(Stream aStrm);
}
发送到该服务的客户端成功调用Test()方法但aStrm抛出异常:
'aStrm.ReadTimeout' threw an exception of type 'System.InvalidOperationException'
我应该使用流来发送正文还是其他内容?
当该合约的配置如下所示时,我可以将数据作为 url 的一部分发送:
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "?s={aStr}")]
string Test(string aStr);
但是这是常见的做法吗?我不应该在逻辑上将内容添加到请求的正文而不是 url 吗?
【问题讨论】: