将故障异常上的命名空间移至信封WCF服务

时间:2014-05-20 16:22:03

标签: c# wcf soap xmlvend

我在挣扎。我正在尝试在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>

是否可能,如果可以,我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

可以在Soap信封(以及消息)中更改名称空间或前缀,但这不是一个简单的配置。请看这里:

Customize WCF Envelope and Namespace Prefix

基本上,您必须编写自定义MessageFormatter或MessageEncoder。从Xml / SOAP的角度来看,命名空间的位置或前缀是什么并不重要,但如果您需要支持一些手动解析响应的旧客户端,则可能需要它。