【问题标题】:Use json body in Soap envelope when sending to WCF service发送到 WCF 服务时在 Soap 信封中使用 json 正文
【发布时间】:2010-09-21 11:59:39
【问题描述】:

我需要与带有 json 主体的 autentication 的肥皂头接口。

我是这样创建合同的:

[ServiceContract(Namespace = "http://tourico.com/webservices/hotelv3")]
public interface IHotelMobileFlow
{
    [OperationContract, WebInvoke(
       BodyStyle = WebMessageBodyStyle.Wrapped,
       RequestFormat = WebMessageFormat.Json,
       ResponseFormat = WebMessageFormat.Json)]
    SearchResultMobile SearchHotels(SearchRequestMobile request);

这样的服务:

[AuthenticationRequired(typeof(HotelFlow), typeof(DefaultClientAuthenticationHandler))]
public class HotelMobileFlow : IHotelMobileFlow
{

对于属性 'AuthenticationRequired' 我需要发送一个肥皂头

<soapenv:Header>
      <aut:AuthenticationHeader>
         <aut:LoginName>host</aut:LoginName>
         <aut:Password>password</aut:Password>
         <aut:Culture>en_US</aut:Culture>
         <aut:Version>8</aut:Version>
      </aut:AuthenticationHeader>
   </soapenv:Header>

我创建了这样的请求:

HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

request.Method = "POST";
request.ContentType = "application/json; charset=utf-8";

SearchRequestMobile sr = new SearchRequestMobile();

是否可以将soap标头添加到json请求中? 还有其他选项如何将标头传输到服务?

谢谢,米哈尔

【问题讨论】:

    标签: wcf json soap httprequest


    【解决方案1】:

    不,不可能将 SOAP 标头添加到 JSON 请求。服务将无法解析它。您的 Web 请求定义您正在发送 JSON。也就是说请求的内容只能是JSON。

    理论上,如果您实现自己的消息编码器,您将能够在 SOAP 正文中发送 JSON 内容并添加 SOAP 标头,但这种开发的复杂性并不值得。

    您必须提供其他方式来验证您的客户。请改用自定义 HTTP 标头。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      相关资源
      最近更新 更多