【问题标题】:Changing WCF Namespace on XML Request在 XML 请求上更改 WCF 命名空间
【发布时间】:2012-02-23 10:44:03
【问题描述】:

我正在使用 WCF 连接到 Apache Web 服务。请求失败,因为服务器无法解析头部信息。我已与服务提供商交谈,他们表示命名空间位于错误的范围内。它们应该在信封上而不是身体上。请问如何在 .NET 中进行更改?

我的要求:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
   <wsCaller>
     <appVersion></appVersion> 
   </wsCaller>
  </s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <addSvcRecord xmlns="http://ws.dsr.careur.com">
    <svcRecord xmlns="">
      <vin>JMZCR19F200100059</vin> 
      <number>10</number> 
      <date>2012-02-22</date> 
      <mileage>38500</mileage> 
      <mileageType>KILOMETERS</mileageType> 
      <invokeErrorPage>false</invokeErrorPage> 
     </svcRecord>
   </addSvcRecord>
</s:Body>
</s:Envelope>

应该看起来更像:

<?xml version="1.0" encoding="UTF-8" ?> 
<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.dsr.careur.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ws="http://ws.dsr.careur.com" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header>
     <ws:wsCaller>
       <appVersion></appVersion> 
     </ws:wsCaller>
   </SOAP-ENV:Header>
 <ns0:Body>
   <ns1:getSvcRecords>
     <vin>JMZDE14K280138989</vin> 
   </ns1:getSvcRecords>
 </ns0:Body>
</SOAP-ENV:Envelope>

【问题讨论】:

  • 你是如何定义标题的?
  • 在我的 web.config 中,我已将其添加到端点: mappsacc.careur.com/dsr-services/dsrWebService" binding="basicHttpBinding" bindingConfiguration="DsrWebServiceSoapBinding" contract="CarDSR.DsrWebService" name="DsrWebServicePort"> 0.1

标签: xml wcf web-services namespaces scope


【解决方案1】:

问题不在于命名空间位于错误的范围内,而是标头不在命名空间中(这并不完全相同)。您需要将标题放在配置文件的命名空间中

<headers> 
  <ws:wsCaller xmlns:ws="http://ws.dsr.careur.com">
     <appVersion>0.1</appVersion>
  </ws:wsCaller> 
</headers> 

【讨论】:

    猜你喜欢
    • 2021-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多