title: Unmarshalling error when connecting to Java-based webservice using VB.NET 4.5.1 client
body: <p>I am trying to build a web application which will read data to/from a database and query and post data to a remote webservice. The web application is written in vb.net on .NET framework 4.5.1. I'm using VS2013 for the IDE.</p>
  
  <p>I added the service "<a href="https://service.provider.com/..../ws/soap?wsdl=SOAP.wsdl" rel="nofollow">https://service.provider.com/..../ws/soap?wsdl=SOAP.wsdl</a>" as a Service Reference and have written the following to query the service:</p>
  
  <pre><code>Dim client As Service1.SOAPClient = New Service1.SOAPClient("Service1Soap")
  
  Dim session = New Service1.session With {.id = 0, .login = "username", .password = "password"}
  
  Dim response = client.openSession(session)              
  
  If response.status = Service1.responseStatus.success Then
      'yay
  ElseIf response.status = Service1.responseStatus.failure Then
      'boo
  End If
  </code></pre>
  
  <p>The service.serviceModel section in the web.config wasn't generated automatically, so I had to manually cobble it together based on the various errors I received each time I ran it. I eventually came up with the following:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="Service1Soap"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
        &lt;customBinding&gt;
          &lt;binding name="Service1Soap12"&gt;
            &lt;textMessageEncoding messageVersion="Soap12" /&gt;
            &lt;httpTransport /&gt;
          &lt;/binding&gt;
        &lt;/customBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
        &lt;endpoint address="https://service.provider.com/.../ws/soap?wsdl=SOAP.wsdl" binding="basicHttpBinding" bindingConfiguration="Service1Soap" contract="Service1.SOAP" name="Service1Soap" /&gt;
      &lt;/client&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>Now, when I run the application it throws an error when it tries to call openSession and gives me the following error message:</p>
  
  <pre><code>Unmarshalling Error: Namespace URIs and local names to the unmarshaller needs to be interned.  
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  
   Exception Details: System.ServiceModel.FaultException: Unmarshalling Error: Namespace URIs and local names to the unmarshaller needs to be interned. 
  
  Source Error:  
  
  Line 7771:        &lt;System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)&gt;  _
  Line 7772:        Function Service1_SOAP_openSession(ByVal request As Service1.openSession) As Service1.openSessionResponse Implements Service1.SOAP.openSession
  Line 7773:            Return MyBase.Channel.openSession(request)
  Line 7774:        End Function
  Line 7775:        
  
  
   Source File:  c:\...\Visual Studio 2013\Projects\WebApplication1\WebApplication1\Service References\Service1\Reference.vb    Line:  7773 
  
  Stack Trace: 
  
  
  
  [FaultException: Unmarshalling Error: Namespace URIs and local names to the unmarshaller needs to be interned. ]
     System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +10733331
     System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type) +336
     WebApplication1.Service1.SOAP.openSession(openSession request) +0
     WebApplication1.Service1.SOAPClient.Service1_SOAP_openSession(openSession request) in c:\...\Projects\WebApplication1\WebApplication1\Service References\Service1\Reference.vb:7773
     WebApplication1.Service1.SOAPClient.openSession(OpenSession openSession1) in c:\...\Visual Studio 2013\Projects\WebApplication1\WebApplication1\Service References\Service1\Reference.vb:7779
  </code></pre>
  
  <p>...</p>
  
  <p>I've queried the webservice using SoapUI and I have captured this as the response from the webservice:</p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;soap:Body&gt;
        &lt;ns1:openSessionResponse xmlns:ns1="http://autogenerated.service.provider.com/"&gt;
           &lt;return xmlns:ns2="http://autogenerated.service.provider.com/"&gt;
              &lt;id&gt;0&lt;/id&gt;
              &lt;status&gt;success&lt;/status&gt;
              &lt;sessionId&gt;8a9b868f4d4650ee014d488308e90243&lt;/sessionId&gt;
           &lt;/return&gt;
        &lt;/ns1:openSessionResponse&gt;
     &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>According to the third-party webservice provider, this error is related to the service being Java-based and me using a vb.net-based client. I apparently need to write a WCF-extension to modify the SOAP requests and responses between the client and server, to remove the namespaces in the SOAP envelope. This is the first time I've done a .net client-to-java webservice project so I don't know where to begin and the service provider can't provide any more specific help.</p>
  
  <p>Does anyone know how to do this?</p>
  
  <p><strong>Update:</strong> I noticed my service url was wrong (it was referencing an imported section). After correcting the url, the web.config generated correctly and now reads as follows, but I still receive the same unmarshalling error above.</p>
  
  <pre><code>  &lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="SOAPSoapBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
        &lt;endpoint address="https://service.provider.com/.../ws/soap"
            binding="basicHttpBinding" bindingConfiguration="SOAPSoapBinding"
            contract="ServiceReference1.SOAP" name="SOAPImplPort" /&gt;
      &lt;/client&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p><strong>Update 2:</strong> Using Fiddler2, I captured the outgoing request to the webservice and the return values. I then used SoapUI to compare the SoapUI query with the .net generated query and edited the query until I got a valid response.</p>
  
  <p><strong>.net-generated query:</strong></p>
  
  <pre><code>&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
       &lt;s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
            &lt;openSession xmlns="http://autogenerated.service.provider.com/"&gt;
                 &lt;openSession xmlns=""&gt;
                      &lt;id&gt;0&lt;/id&gt;
                      &lt;login&gt;username&lt;/login&gt;
                      &lt;password&gt;password&lt;/password&gt;
                 &lt;/openSession&gt;
           &lt;/openSession&gt;
       &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>
  
  <p><strong>Webservice response:</strong></p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;soap:Body&gt;
        &lt;soap:Fault&gt;
           &lt;faultcode&gt;soap:Client&lt;/faultcode&gt;
           &lt;faultstring&gt;Unmarshalling Error: Namespace URIs and local names to the unmarshaller needs to be interned.&lt;/faultstring&gt;
        &lt;/soap:Fault&gt;
     &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p><strong>edited and working .net query in soap ui:</strong>
  Note removal of namespace attribues from the openSession tags.</p>
  
  <pre><code>&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
       &lt;s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
            &lt;openSession&gt;
                 &lt;openSession&gt;
                      &lt;id&gt;0&lt;/id&gt;
                      &lt;login&gt;username&lt;/login&gt;
                      &lt;password&gt;password&lt;/password&gt;
                 &lt;/openSession&gt;
            &lt;/openSession&gt;
       &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>
  
  <p><strong>Webservice response:</strong></p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;soap:Body&gt;
        &lt;ns1:openSessionResponse xmlns:ns1="http://autogenerated.service.provider.com/"&gt;
           &lt;return xmlns:ns2="http://autogenerated.service.provider.com/"&gt;
              &lt;id&gt;0&lt;/id&gt;
              &lt;status&gt;success&lt;/status&gt;
              &lt;sessionId&gt;8a9b868f4d55c42b014d56f00c990134&lt;/sessionId&gt;
           &lt;/return&gt;
        &lt;/ns1:openSessionResponse&gt;
     &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p><strong>So, the question is now:</strong> how do I modify the outgoing query from my client application before it is sent to the webservice, to remove the namespaces?</p>
  
  <p><strong>Update 3:</strong> Success! I've managed to remove the namespaces by editing the Reference.vb file and setting the WrapperNamespace and Namespace attributes, on the specific methods that I needed to call, to "" instead of "<a href="http://autogenerated.service.provider.com/" rel="nofollow">http://autogenerated.service.provider.com/</a>". I then copied these into a partial class within the same namespace and commented out the auto-generated methods within the auto-generated proxy class. If the proxy class is ever regenerated in future then it will give me a build error and I just have to remove/comment them out again. The client now calls the webservice with no problems.</p>
  
  <p><strong>CustomReference.vb:</strong></p>
  
  <pre><code>Namespace ServiceReference1
  
      &lt;System.Diagnostics.DebuggerStepThroughAttribute(), _
           System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"), _
           System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced), _
           System.ServiceModel.MessageContractAttribute(WrapperName:="openSession", WrapperNamespace:="", IsWrapped:=True)&gt; _
      Partial Public Class openSession
  
          &lt;System.ServiceModel.MessageBodyMemberAttribute(Name:="openSession", [Namespace]:="", Order:=0), _
           System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)&gt; _
          Public openSession1 As ServiceReference1.OpenSession
  
          Public Sub New()
              MyBase.New()
          End Sub
  
          Public Sub New(ByVal openSession1 As ServiceReference1.OpenSession)
              MyBase.New()
              Me.openSession1 = openSession1
          End Sub
      End Class
  ...
  End Namespace
  </code></pre>
  
  <p>However, is there a better approach?</p>