How do I declare a blank namespace with the .NET components?

SunsetSunset Member Posts: 201
I've been asked to create a piece of code that connects to a webservice, sends some information and handles the response.
Sending and collecting the response goes fine, but when trying to handle the response, I'm stomped by a blank namespace declaration :(

The responsexml I get is:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
<s:Body>
<SendOrderResponse xmlns="http://tempuri.org/"&gt;
<SendOrderResult xmlns:a="http://schemas.datacontract.org/2004/07/Scalepoint.Web.EasyClaims.Webservices.DealerManagement&quot; xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
<a:Description>...</a:Description>
<a:ResultCode>SCHEMA_VALIDATION_ERROR</a:ResultCode>
<a:ResultDetails i:nil="true"/>
</SendOrderResult>
</SendOrderResponse>
</s:Body>
</s:Envelope>

To handle this I have:
// Create NameSpacemanager
XmlNamespaceManager := XmlNamespaceManager.XmlNamespaceManager(XmlDocument.NameTable);
XmlNamespaceManager.AddNamespace('s','http://schemas.xmlsoap.org/soap/envelope/');
XmlNamespaceManager.AddNamespace('','http://tempuri.org/');
XmlNamespaceManager.AddNamespace('a','http://schemas.datacontract.org/2004/07/Scalepoint.Web.EasyClaims.Webservices.DealerManagement');
XmlNamespaceManager.AddNamespace('i','http://www.w3.org/2001/XMLSchema-instance');

and then I want to do a:
//Find ResponseCode
XmlCurrNode := XmlDocument.SelectSingleNode('s:Envelope/s:Body/SendOrderResponse/SendOrderResult/a:ResultCode', XmlNamespaceManager);

Doing a SelectSingleNode on just 's:Body' works, as does selecting 's:Envelope/s:Body'.
But as soon as I go to the SendOrderResponse my Node is uninitialized :(
I suspect I'm using/declaring the manager incorrectly, so any pointers would be welcome.
Don't just take my word for it, test it yourself

Best Answer

Answers

  • RockWithNAVRockWithNAV Member Posts: 1,139
    Hey Sunset,

    Sorry if i misunderstood something. If you want to remove namespace from the response then you can check out the below link.

    https://rockwithnav.wordpress.com/2016/03/29/remove-namespace-web-service-response-dotnet-variable/
  • SunsetSunset Member Posts: 201
    I don't really want the namespaces removed, just to be able to select the node.

    Your method looks like it would work; at least without any namespaces I should be able to grab the various nodes as needed. Unfortunately I cannot find the MSXML.DOMDocumentClass component on the clients machine, so I can't use that option.
    Don't just take my word for it, test it yourself
  • SunsetSunset Member Posts: 201
    That cleared up something about namespaces for me; thank you :)

    Unfurtunately it didn't seem to help :(
    I have changed the tempuri to:
    XmlNamespaceManager.AddNamespace('blank','http://tempuri.org/')
    and am now asking for
    XmlDocument.SelectSingleNode('s:Envelope/s:Body/blank:SendOrderResponse/blank:SendOrderResult/a:ResultCode', XmlNamespaceManager)

    But still it won't find anything for me.
    Don't just take my word for it, test it yourself
  • SunsetSunset Member Posts: 201
    What I wrote turned out to be not exactly correct :)
    I was using a node to select from, which didn't work. But if I use the XmlDocument it works fine.
    Thank you vaprog
    Don't just take my word for it, test it yourself
Sign In or Register to comment.