【问题标题】:Is there any Rest Envelope like SOAP Envelope?有没有像 SOAP Envelope 这样的 Rest Envelope?
【发布时间】:2013-09-09 11:23:42
【问题描述】:

消息如何在 WCF REST 服务中传输?有没有休息信封?请提出建议。

【问题讨论】:

  • 没有信封。它完全取决于 HTTP:uri、标头、http 方法等

标签: .net wcf web-services rest


【解决方案1】:

REST Web 服务没有信封结构,而只是利用 Http(地址、方法、标头、正文)。

可以使用以下方式访问 Http 标头:

WebOperationContext.Current.IncomingRequest.Headers  

可以使用以下方式访问 Http 消息体:

OperationContext.Current.RequestContext.RequestMessage  

为了更彻底地理解/可视化 REST Web 服务消息结构,您可以托管一个简单的 WCF Rest Web 服务,启用跟踪,然后发送一些消息。跟踪文件将显示 Http 消息(标头和正文),如下所示:

<HttpRequest xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
<Method>POST</Method>
<QueryString></QueryString>
<WebHeaders>
<Connection>close</Connection>
<Content-Length>10531</Content-Length>
<Content-Type>application/xml</Content-Type>
<Accept>*/*</Accept>
<Accept-Encoding>gzip;q=1.0,deflate;q=0.6,identity;q=0.3</Accept-Encoding>
<Host>127.0.0.1:18100</Host>
<User-Agent>Ruby</User-Agent>
</WebHeaders>

注意:如果您需要其他实施信息,以下链接提供了 WCF Rest Web 服务实施的相当全面和直接的概述:
http://www.codeproject.com/Articles/571813/A-Beginners-Tutorial-on-Creating-WCF-REST-Services

问候,

【讨论】:

    猜你喜欢
    • 2021-01-14
    • 2014-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    • 2021-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多