在WCF REST风格的服务访问请求体 [英] Access Request Body in a WCF RESTful Service
本文介绍了在WCF REST风格的服务访问请求体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何访问HTTP POST请求主体在WCF REST服务
How do I access the HTTP POST request body in a WCF REST service?
下面是服务定义:
[ServiceContract]
public interface ITestService
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "EntryPoint")]
MyData GetData();
}
下面是执行:
public MyData GetData()
{
return new MyData();
}
不过,我觉得用下面的代码来访问HTTP请求的:
I though of using the following code to access the HTTP request:
IncomingWebRequestContext context = WebOperationContext.Current.IncomingRequest;
但IncomingWebRequestContext只允许访问标题,而不是身体。
But the IncomingWebRequestContext only gives access to the headers, not the body.
感谢。
推荐答案
我觉得不涉及WebOperationContext的最佳方式。
Best way i think doesn't involve WebOperationContext
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "EntryPoint", BodyStyle = WebMessageBodyStyle.Bare)]
MyData GetData(System.IO.Stream pStream);
这篇关于在WCF REST风格的服务访问请求体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文