none
Issue with namespace prefix in SOAP request RRS feed

  • Question

  • Hi,

    I am implementing a WCF web service which interacts with a client whose code I do not control. 
    I generated the service contract from the WSDL using svcutil.
    The WSDL was supplied by the client.
    The following is an example of the soap request sent by the client (note the presence of the ns2 prefix in the request): 

    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
     <soap:Body>
      <ns2:sendSpaRequestFlow xmlns:ns2="http://mynamespace.com/">
       <arg0>
        <actionCode>A</actionCode>
        <spaRequest>
         <id>a5CK0000000CaWOMA0</id>
        </spaRequest>
       </arg0>
      </ns2:sendSpaRequestFlow>
     </soap:Body>
    </soap:Envelope>

    If I request the service using a soap request with these prefix the request fails with a null pointer on the spaRequest object received by the sendSpaRequestFlow operation.
    However, if I manually remove the ns2 prefix, the spaRequest object appears not to be null.

    The following blocks:

    <ns2:sendSpaRequestFlow xmlns:ns2="http://mynamespace.com/">

    and

    <sendSpaRequestFlow xmlns="http://mynamespace.com/">
    are not supposed to be exactly the same according to xml standard? Could someone help me understand why my WCF service can not  properly consume the Soap request with the ns2 namespace prefix?


    Thanks in advance.

    Monday, May 20, 2013 12:51 PM

Answers

  • The difference isn't in the "sendSpaRequestFlow" element - as you stated, that element itself is (semantically) the same in the first and second examples shown below.

    All the children nodes, however, are different. In the first case, the only element in the 'http://mynamespace.com' namespace is the element 'sendSpaRequestFlow'. All its children (arg0, actionCode, spaRequest, etc.) are in the default (empty) namespace. In the second case, the xmlns declaration actually redefined the default namespace. So in that case, not only the 'sendSpaRequestFlow' element, but also all of its children elements are in that namespace. That's likely why the service isn't able to consume that request.

    What you could do is to, after defining the default namespace on the 'sendSpaRequestFlow' element, redefining it to its original value, as shown in the third example below (assuming that the default namespace was actually ""). Notice that you'd need to redefine the default namespace in each child element of the 'sendSpaRequestFlow' (in your example there's only one, 'arg0', but if there were other argN, the namespace would need to be redefined there as well).

     <first>
      <ns2:sendSpaRequestFlow xmlns:ns2="http://mynamespace.com/">
       <arg0>
        <actionCode>A</actionCode>
        <spaRequest>
         <id>a5CK0000000CaWOMA0</id>
        </spaRequest>
       </arg0>
      </ns2:sendSpaRequestFlow>
     </first>
     <second>
      <sendSpaRequestFlow xmlns="http://mynamespace.com/">
       <arg0>
        <actionCode>A</actionCode>
        <spaRequest>
         <id>a5CK0000000CaWOMA0</id>
        </spaRequest>
       </arg0>
      </sendSpaRequestFlow>
     </second>
     <third>
      <sendSpaRequestFlow xmlns="http://mynamespace.com/">
       <arg0 xmlns="">
        <actionCode>A</actionCode>
        <spaRequest>
         <id>a5CK0000000CaWOMA0</id>
        </spaRequest>
       </arg0>
      </sendSpaRequestFlow>
     </third>


    Carlos Figueira

    • Marked as answer by Ana56 Tuesday, May 21, 2013 1:37 PM
    Monday, May 20, 2013 10:28 PM
    Moderator
  • Thank you very much for your help Carlos,

    I better understand the use of namespace now.
    I could solve my problem by removing the definition of the namespace in my service contract so the elements inside 'sendSpaRequestFlow' are not anymore defined in the namespace.

    Elements inside the node 'sendSpaRequestFlow' do not belong to a namespace according to the WSDL file (so xmlns="" for arg0 as you stated in your third example). So it was a mistake to add the namespace directly to the service contract.


    • Edited by Ana56 Tuesday, May 21, 2013 1:39 PM
    • Marked as answer by Ana56 Tuesday, May 21, 2013 1:43 PM
    Tuesday, May 21, 2013 1:37 PM

All replies

  • The difference isn't in the "sendSpaRequestFlow" element - as you stated, that element itself is (semantically) the same in the first and second examples shown below.

    All the children nodes, however, are different. In the first case, the only element in the 'http://mynamespace.com' namespace is the element 'sendSpaRequestFlow'. All its children (arg0, actionCode, spaRequest, etc.) are in the default (empty) namespace. In the second case, the xmlns declaration actually redefined the default namespace. So in that case, not only the 'sendSpaRequestFlow' element, but also all of its children elements are in that namespace. That's likely why the service isn't able to consume that request.

    What you could do is to, after defining the default namespace on the 'sendSpaRequestFlow' element, redefining it to its original value, as shown in the third example below (assuming that the default namespace was actually ""). Notice that you'd need to redefine the default namespace in each child element of the 'sendSpaRequestFlow' (in your example there's only one, 'arg0', but if there were other argN, the namespace would need to be redefined there as well).

     <first>
      <ns2:sendSpaRequestFlow xmlns:ns2="http://mynamespace.com/">
       <arg0>
        <actionCode>A</actionCode>
        <spaRequest>
         <id>a5CK0000000CaWOMA0</id>
        </spaRequest>
       </arg0>
      </ns2:sendSpaRequestFlow>
     </first>
     <second>
      <sendSpaRequestFlow xmlns="http://mynamespace.com/">
       <arg0>
        <actionCode>A</actionCode>
        <spaRequest>
         <id>a5CK0000000CaWOMA0</id>
        </spaRequest>
       </arg0>
      </sendSpaRequestFlow>
     </second>
     <third>
      <sendSpaRequestFlow xmlns="http://mynamespace.com/">
       <arg0 xmlns="">
        <actionCode>A</actionCode>
        <spaRequest>
         <id>a5CK0000000CaWOMA0</id>
        </spaRequest>
       </arg0>
      </sendSpaRequestFlow>
     </third>


    Carlos Figueira

    • Marked as answer by Ana56 Tuesday, May 21, 2013 1:37 PM
    Monday, May 20, 2013 10:28 PM
    Moderator
  • Thank you very much for your help Carlos,

    I better understand the use of namespace now.
    I could solve my problem by removing the definition of the namespace in my service contract so the elements inside 'sendSpaRequestFlow' are not anymore defined in the namespace.

    Elements inside the node 'sendSpaRequestFlow' do not belong to a namespace according to the WSDL file (so xmlns="" for arg0 as you stated in your third example). So it was a mistake to add the namespace directly to the service contract.


    • Edited by Ana56 Tuesday, May 21, 2013 1:39 PM
    • Marked as answer by Ana56 Tuesday, May 21, 2013 1:43 PM
    Tuesday, May 21, 2013 1:37 PM