根据 XML 请求更改 WCF 命名空间
我正在使用 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>
I am using WCF to connect to an Apache web service. The request fails because the server cannot parse the header information. I have spoken to the provider of the service and they have indicated that the namespaces are in the wrong scope. They should be on the envelope not the body. How do I change this in .NET please?
My request:
<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>
Should look more like:
<?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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题不在于命名空间位于错误的范围内,而是标头不在命名空间中(这不完全相同)。您需要将标头放入配置文件的命名空间中
The problem isn't that the namespace is at the wrong scope, its that the header isn't in the namespace (which isn't quite the same thing). You need to put your header in the namespace in the config file