如何在WCF请求上设置content-Type

时间:2014-12-18 20:18:52

标签: soap http-headers

我的问题是像Google Postman(awesome tool, found here)这样的测试应用可以发送消息。 当我发送邮件时,它始终被拒绝(完全相同的邮件),因为当邮件过期时#39;

所以我发送它的方式肯定会有所不同......

有......内容类型不同,一个......但不确定这是不是......

我已经看到了一些关于访问端点行为的提示,例如:

 var whb = client.ChannelFactory.Endpoint.Behaviors.Find<WebHttpBehavior>();

但这只允许我在xml和json之间进行选择。

whb.AutomaticFormatSelectionEnabled = false;
whb.DefaultOutgoingRequestFormat = WebMessageFormat.Xml;

我有一个wsdl:

http://caqh.org/SOAP/WSDL/CORERule2.2.0.wsdl

我需要使用以下标题调用WCF服务的RealTimeTransaciton:

Content-Type: application/soap+xml;charset=UTF-8;

目前,我认为默认情况下,呼叫包括标题;

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

和Content-Type似乎没有设置。

所以我试图影响请求的标题......

        var addressHeaders =      new    List<AddressHeader>     {
            AddressHeader.CreateAddressHeader("Content-Type", "", "application/soap+xml;charset=UTF-8;"),
            AddressHeader.CreateAddressHeader("Cache-Control", "", "no-cache"),
            AddressHeader.CreateAddressHeader("Accept", "", "application/soap+xml;charset=UTF-8;")
        };


        var client = new CORETransactionsClient(binding, new EndpointAddress(new Uri(url),addressHeaders.ToArray()));

但令我惊讶的是,结果就是这些标题&#39;在soap信封标题中添加,而不是传输的标题!

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <s:Header>
        <Content-Type>application/soap+xml;charset=UTF-8;</Content-Type>
        <Cache-Control>no-cache</Cache-Control>
        <Accept>application/soap+xml;charset=UTF-8;</Accept>
        <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">

等....大声笑

我的web.config服务模型:

<system.serviceModel>
  <bindings>
    <customBinding>
      <binding name="CoreSoapBinding">
        <textMessageEncoding messageVersion="Soap12" writeEncoding="UTF8" />
      </binding>
    </customBinding>
  </bindings>
  <client>
    <endpoint address="https://my_vendor_url_for_service_that_is_Axis2_based" binding="customBinding"
      bindingConfiguration="CoreSoapBinding" contract="CoreRule.CORETransactions"
      name="CoreSoapPort"
      endpointConfiguration="">
    </endpoint>
  </client>
</system.serviceModel>

我如何打电话:

var msg = Create270X12Message(requestReferenceId, senderId, receiverId, requestDateStr, productionCall, prettyOutput);

var envelope = new COREEnvelopeRealTimeRequest
{
    CORERuleVersion = "2.2.0",
    Payload = string.Format("<![CDATA[{0}]]>", Convert.ToBase64String(Encoding.UTF8.GetBytes(msg))),
    PayloadID = requestReferenceId.ToString(),
    PayloadType = CoreRule2PayloadType_270_5010,
    ProcessingMode = CoreRule2ProcessingMode_270_5010,
    ReceiverID = receiverId,
    SenderID = senderId,
    TimeStamp = requestDateStr
 };

 var client = CreateRealTimeOnlineProxy(urlMissouiri, username, password, requestDateStr);

 var response = client.RealTimeTransaction(envelope);

如何将我的标头集合添加到请求本身,而不是SOAP Envelope标头?

0 个答案:

没有答案