0

I am struggling. I am trying to implement a custom fault in WCF.

I would like to move the namespace from the Fault Contract class to the envelope

Currently :

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

and what it should be

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

Is it possible and if so how would I be able to do it?

1 Answers1

0

It is possible to alter the namespaces or prefixes in Soap envelope (and also in messages), but it is not a simple configuration. Please take a look here:

Customize WCF Envelope and Namespace Prefix

Basically, you'll have to write a custom MessageFormatter or MessageEncoder. From Xml/SOAP point of view, it doesn't matter where the namespace is or what the prefix is, but if you need to support some old clients who manually parse the response, you might need it.

Cosmin Vană
  • 1,562
  • 12
  • 28