mercredi 12 août 2015

Why does .NET XMLSerializer automatically change my namespace prefixes (alias)?

I am working on a web service that needs to return faults in a way that is defined by the standards of our type of business. This requires me to return a fault as this:

<soap:Envelope xmlns:soap="http://ift.tt/sVJIaE">
  <soap:Header>
  <wsse:Security xmlns="http://ift.tt/LRW8Ij">
    <Timestamp xmlns="http://ift.tt/Hm2joJ" />
  </wsse:Security>
  </soap:Header>
  <soap:Body xmlns:xsi="http://ift.tt/ra1lAU" xmlns:xsd="http://ift.tt/tphNwY">
    <soap:Fault>
      <faultcode>s:Server</faultcode>
      <faultstring>Operator/operand type mismatch.</faultstring>
      <faultactor>urn:dealernumberID:??????</faultactor>
      <detail>
        <ErrorType xmlns="http://ift.tt/1v48JDf">Backend Client Fault</ErrorType>
        <ErrorDetail xmlns="http://ift.tt/1v48JDf">Backend client returned a fault</ErrorDetail>
      </detail>
   </soap:Fault>
  </soap:Body>
</soap:Envelope>

I create the fault like this, but when the service sends it, it looks like this:

<s:Envelope xmlns:s="http://ift.tt/sVJIaE">
  <s:Header>
    <h:Security xmlns="http://ift.tt/LRW8Ij" xmlns:xsd="http://ift.tt/tphNwY" xmlns:xsi="http://ift.tt/ra1lAU" xmlns:h="http://ift.tt/LRW8Ij">
      <Timestamp xmlns="http://ift.tt/Hm2joJ" />
    </h:Security>
  </s:Header>
  <s:Body xmlns:xsi="http://ift.tt/ra1lAU" xmlns:xsd="http://ift.tt/tphNwY">
    <s:Fault>
      <faultcode>s:Server</faultcode>
      <faultstring>Operator/operand type mismatch.</faultstring>
      <faultactor>urn:dealernumberID:??????</faultactor>
      <detail>
        <ErrorType xmlns="http://ift.tt/1v48JDf">Backend Client Fault</ErrorType>
        <ErrorDetail xmlns="http://ift.tt/1v48JDf">Backend client returned a fault</ErrorDetail>
      </detail>
    </s:Fault>
  </s:Body>
</s:Envelope>

Why does this happen? Is there a setting that I can change in .NET to keep it from doing this by default? I do understand that a namespace is a namespace regardless of the prefix, but like I said, the standard dictates we do it a certain way (most likely to accommodate third parties that are reading responses as strings?)

Thanks for any help!




Aucun commentaire:

Enregistrer un commentaire