1

We have a SOAP service that specifies the namespace for the whole content but not the underlying types in the list. The effect is that the message can be mapped (using the good, old WSDL) but the list in that response comes empty (although the items are read) due to failed mapping.

The WSDL contains all the definitions as supposed to. The first xmlns value is correct too (verified against the autocreated proxy client reference). It's just a glitch in the second xmlns definition as it's empty. So while FindUsersByUserIdResponse is type declared, users is not.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <FindUsersByUserIdResponse xmlns="uri:wspisa.ams.se">
      <users xmlns="">
        <user>
          <userId>197602081116</userId>
          <globalAttributes/>
          <applicationAttributes/>
        </user>
      </users>
    </FindUsersByUserIdResponse>
  </soapenv:Body>
</soapenv:Envelope>

The person responsible for said service is gone looong time ago. The complexity of logic makes it difficult to restructure the workflow. The best shot I have is to read in the full content of the envelope as plain text and start parsing manually. However, it's so against everything that's good on this Earth.

I've googled without finding anything more useful and before I start coding the atrocity of manual and custom XML-mapping, I wonder if there's a quicker way. Perhaps by altering the attributed namespaces in the Reference.cs file that points out the namespaces in the SOAP envelope.

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438

1 Answers1

0

If the server side is sending responses that are not matching the contract (wsdl) and there is no option to fix that you could decide to alter the contract single sided on the client side and import that into your code. If you update the contract so that the defined response matches the actual output of the message you will get the data.

If this is difficult due to complex structures and imports you can also decide to change the response contract to accept an xsd:any element basically allowing any syntactic correct xml below that part. This will give you the message regardless of the content. Then you can grab that part and manually set the correct namespace on the message and validate it against the correct data structure.

martijn
  • 485
  • 2
  • 9
  • The structure isn't very complex or convoluted, so the first option you mention might be a good approach. However, I'm not sure how to do so when dealing with the actual case. How would I alter the code (probably the file *Reference.cs* where the contract is declared) to make it map the data with wrong namespace (the empty one) into the class structure I have autogenerated by reading the WSDL file? – Konrad Viltersten Jan 12 '21 at 19:30
  • I would change the response layout described in the wsdl and reimport the wsdl in the code. If you make changes to generated code they could get overwritten in the future. – martijn Jan 13 '21 at 05:51
  • Good suggestion. My issue is that I don't see what I'm supposed to type in the file. The namespace, as shown in the sample in the question, doesn't specify any value at all. And I can't alter what's emitted from the server. So the issue is *what to put in the WSDL or Reference.cs to map the no-name namespace?* in this case. – Konrad Viltersten Jan 13 '21 at 07:06