<p>I have an ASP.NET webservice with along the lines of:</p>

<pre><code>[WebService(Namespace = "http://internalservice.net/messageprocessing")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class ProvisioningService : WebService
{
    [WebMethod]
    public XmlDocument ProcessMessage(XmlDocument message)
    {
        // ... do stuff
    }
}
</code></pre>

<p>I am calling the web service from ASP using something like:</p>

<pre><code>provWSDL = "http://servername:12011/MessageProcessor.asmx?wsdl"
Set service = CreateObject("MSSOAP.SoapClient30")
service.ClientProperty("ServerHTTPRequest") = True
Call service.MSSoapInit(provWSDL)

xmlMessage = "&lt;request&gt;&lt;task&gt;....various xml&lt;/task&gt;&lt;/request&gt;"
result = service.ProcessMessage(xmlMessage)
</code></pre>

<p>The problem I am encountering is that when the XML reaches the ProcessMessage method, the web service plumbing has added a default namespace along the way. i.e. if I set a breakpoint inside ProcessMessage(XmlDocument message) I see:</p>

<pre><code>&lt;request xmlns="http://internalservice.net/messageprocessing"&gt;
  &lt;task&gt;....various xml&lt;/task&gt; 
&lt;/request&gt;
</code></pre>

<p>When I capture packets on the wire I can see that the XML sent by the SOAP toolkit is slightly different from that sent by the .NET WS client. The SOAP toolkit sends:</p>

<pre><code>&lt;SOAP-ENV:Envelope 
    xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" 
    xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;SOAP-ENV:Body&gt;
        &lt;ProcessMessage xmlns="http://internalservice.net/messageprocessing"&gt;
            &lt;message xmlns:SOAPSDK4="http://internalservice.net/messageprocessing"&gt;
                &lt;request&gt;
                    &lt;task&gt;...stuff to do&lt;/task&gt;
                &lt;/request&gt;
            &lt;/message&gt;
        &lt;/ProcessMessage&gt;
    &lt;/SOAP-ENV:Body&gt;
&lt;/SOAP-ENV:Envelope&gt;
</code></pre>

<p>Whilst the .NET client sends:</p>

<pre><code>&lt;soap:Envelope 
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;soap:Body&gt;
        &lt;ProcessMessage xmlns="http://internalservice.net/messageprocessing"&gt;
            &lt;message&gt;
                &lt;request xmlns=""&gt;
                    &lt;task&gt;...stuff to do&lt;/task&gt;
                &lt;/request&gt;
            &lt;/message&gt;
        &lt;/ProcessMessage&gt;
    &lt;/soap:Body&gt;
&lt;/soap:Envelope&gt;
</code></pre>

<p>It's been so long since I used the ASP/SOAP toolkit to call into .NET webservices, I can't remember all the clever tricks/SOAP-fu I used to pull to get around stuff like this.</p>

<p>Any ideas? One solution is to knock up a COM callable .NET proxy that takes the XML as a string param and calls the WS on my behalf, but it's an extra layer of complexity/work I hoped not to do.</p>

[{'answer_id': 19324, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 0, 'selected': False, 'text': '<p>I take it you have access to the Services code, not just the consuming client right?</p>\n\n<p>Just pull the namespace out of the XmlDocument as the first part of the method.</p>\n\n<p>Something like:</p>\n\n<pre><code>XmlDocument changeDocumentNamespace(XmlDocument doc, string newNamespace) \n{   \n    if (doc.DocumentElement.NamespaceURI.Length &gt; 0) \n    {\n        doc.DocumentElement.SetAttribute("xmlns", newNameSpace);\n        XmlDocument newDoc = new XmlDocument();\n        newDoc.LoadXml(doc.OuterXml);\n        return newDoc;\n    }\n    else \n    {\n        return doc;\n    }\n}\n</code></pre>\n\n<p>Then:</p>\n\n<pre><code>[WebService(Namespace = "http://internalservice.net/messageprocessing")]\n[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]\n[ToolboxItem(false)]\npublic class ProvisioningService : WebService\n{\n    [WebMethod]\n    public XmlDocument ProcessMessage(XmlDocument message)\n    {\n        message = changeDocumentNamespace(message,String.Empty);\n        // Do Stuff...\n    }\n}\n</code></pre>\n'}, {'answer_id': 19328, 'author': 'Kev', 'author_id': 419, 'author_profile': 'https://Stackoverflow.com/users/419', 'pm_score': 1, 'selected': True, 'text': '<p>I solved this:</p>\n\n<p>The SOAP client <em>request</em> node was picking up the default namespace from:</p>\n\n<pre><code>&lt;ProcessMessage xmlns="http://internalservice.net/messageprocessing"&gt;\n</code></pre>\n\n<p>Adding an empty default namespace to the XML sent by the ASP client overrides this behaviour:</p>\n\n<pre><code>xmlMessage = "&lt;request xmlns=\'\'&gt;&lt;task&gt;....various xml&lt;/task&gt;&lt;/request&gt;"\n</code></pre>\n'}, {'answer_id': 19352, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 1, 'selected': False, 'text': '<p>Kev,</p>\n\n<p>I found the solution, but its not trivial.</p>\n\n<p>You need to create a custom implementation of IHeaderHandler that creates the proper headers.</p>\n\n<p>There is a good step by step here:</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/ms980699.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms980699.aspx</a></p>\n\n<p>EDIT: I saw your update. Nice workaround, you might want to bookmark this link regardless :D</p>\n'}]
['https://Stackoverflow.com/questions/19318', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/419/']