将故障异常的名称空间移动到信封WCF服务
本文关键字:WCF 服务 移动 空间 异常 故障 | 更新日期: 2023-09-27 18:04:20
我很挣扎。我正试图在WCF中实现自定义错误。
我想将名称空间从Fault Contract类移动到信封
目前:<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring xml:lang="en-ZA">This meter has been blocked</faultstring>
<detail>
<xmlvendFaultResp xmlns="http://www.nrs.eskom.co.za/xmlvend/service/2.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:b="http://www.extended.net/AccountExtensions"
xmlns:ns1="http://www.nrs.eskom.co.za/xmlvend/base/2.1/schema">
<ns1:clientID xsi:type="ns1:EANDeviceID" ean="4466122376268"/>
<ns1:serverID xsi:type="ns1:EANDeviceID" ean="6004708001998"/>
<ns1:terminalID xsi:type="ns1:GenericDeviceID" id="1"/>
<ns1:reqMsgID dateTime="20140506132252" uniqueNumber="100003"/>
<ns1:respDateTime>2014-05-20T17:46:21.8611498+02:00</ns1:respDateTime>
<ns1:dispHeader>This meter has been blocked</ns1:dispHeader>
<ns1:operatorMsg>This meter has been blocked</ns1:operatorMsg>
<ns1:custMsg>This meter has been blocked</ns1:custMsg>
<ns1:fault xsi:type="ns1:BlockedMeterEx">
<ns1:desc>This meter has been blocked</ns1:desc>
</ns1:fault>
</xmlvendFaultResp>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
和应该是什么
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://www.nrs.eskom.co.za/xmlvend/base/2.1/schema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring xml:lang="en-ZA">This meter has been blocked</faultstring>
<detail>
<ns1:xmlvendFaultResp>
<ns1:clientID xsi:type="ns1:EANDeviceID" ean="4466122376268"/>
<ns1:serverID xsi:type="ns1:EANDeviceID" ean="6004708001998"/>
<ns1:terminalID xsi:type="ns1:GenericDeviceID" id="1"/>
<ns1:reqMsgID dateTime="20140506132252" uniqueNumber="100003"/>
<ns1:respDateTime>2014-05-20T17:46:21.8611498+02:00</ns1:respDateTime>
<ns1:dispHeader>This meter has been blocked</ns1:dispHeader>
<ns1:operatorMsg>This meter has been blocked</ns1:operatorMsg>
<ns1:custMsg>This meter has been blocked</ns1:custMsg>
<ns1:fault xsi:type="ns1:BlockedMeterEx">
<ns1:desc>This meter has been blocked</ns1:desc>
</ns1:fault>
</xmlvendFaultResp>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
有可能吗?如果有可能,我怎么才能做到呢?
可以更改Soap信封(以及消息)中的名称空间或前缀,但这不是一个简单的配置。请看这里:
自定义WCF信封和命名空间前缀
基本上,你必须编写一个自定义的MessageFormatter或MessageEncoder。从Xml/SOAP的角度来看,名称空间在哪里或前缀是什么并不重要,但如果需要支持一些手动解析响应的旧客户机,则可能需要它。