2012-02-23 61 views
0

我正在使用WCF連接到Apache Web服務。請求失敗,因爲服務器無法解析標題信息。我已經和服務提供者談過了,他們已經指出名字空間的範圍是錯誤的。它們應該放在信封上而不是身體上。如何在.NET中更改此項?在XML請求上更改WCF名稱空間

我的要求:

<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> 
+0

你是如何定義頭文件的? – 2012-02-23 11:21:40

+0

在我的web.config我已經把它添加到端點: <端點地址= 「https://mappsacc.careur.com/dsr-services/dsrWebService」 綁定= 「basicHttpBinding的」 bindingConfiguration = 「DsrWebServiceSoapBinding」 合同= 「CarDSR.DsrWebService」 NAME = 「DsrWebServicePort」> 0.1 Zymotik 2012-02-23 11:48:23

回答

3

的問題不是該命名空間是在錯誤的範圍,它的頭是不是在命名空間(這不是一回事)。你需要把你的頭文件放在配置文件的命名空間中

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

感謝您!有效! – Zymotik 2012-02-27 15:24:41