title: How to parse a soap message loaded from a file?
body: <p>I need to parse a SOAP message I load from the disk, to the type of the generated proxy. WCF does it when it receives the message from the http server, so I should be able to do it from the disk.</p>
  
  <p>I consume a webservice with WCF, I generated the proxy client from the remote WSDL.</p>
  
  <p>Here is the XML structure I received from the network (it was logged with System.ServiceModel.MessageLogging) that I want to parse to the generated class CRResponse.: </p>
  
  <pre><code>&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="urn:PourtuIntf" xmlns:ns2="ns2:PourtuIntf-IPourtu"&gt;
     &lt;SOAP-ENV:Header/&gt;
     &lt;SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;
        &lt;ns2:GetCRResponse&gt;
           &lt;return&gt;
              &lt;ResultCode&gt;0&lt;/ResultCode&gt;
              &lt;CR&gt;
                 &lt;Theme SOAP-ENC:arrayType="ns1:ItemType[5]"&gt;
                    &lt;item&gt;
                       &lt;Key/&gt;
                       &lt;Section SOAP-ENC:arrayType="ns1:Section[3]"&gt;
  ...
  </code></pre>
  
  <p>When I call the operation 'GetCR' of the web service, the message is correctly converted to the WCF generated proxy client type GetCRResponse, but I don't knwo how WCF works and I need to parse the file from the disk.</p>
  
  <p>I tried to parse the message that way:</p>
  
  <pre><code>  GetCRResponse body;
    using (var xmlReader =  XmlReader.Create("Requests\\CR.xml"))
    {
        Message m = Message.CreateMessage(xmlReader, int.MaxValue, MessageVersion.Soap11);
        body = m.GetBody&lt;GetCRResponse&gt;();
    }
  </code></pre>
  
  <p>In the GeyBody method this exception is raised:</p>
  
  <p><code>Expected element 'ActGetCRResponse' from namespace 'http://schemas.datacontract.org/2004/07/Pourtu.PourtuClient'.. Detecting 'Element' with name 'ActGetCRResponse', namespace 'urn:PourtuIntf-IPourtu'</code>.</p>
  
  <p>I tried using the SoapFormatter:</p>
  
  <pre><code>using ( FileStream fs = new FileStream("Requests\\CR.xml", FileMode.Open) )
  {
      SoapFormatter formatter = new SoapFormatter();
      body = (ActGetCRResponse)formatter.Deserialize(fs);
  }
  </code></pre>
  
  <p>..the Deserialize throws the following exception: Analysis error, no assembly associated to the xml key 'ns2 GetCRResponse'.</p>
  
  <p>I cannot use the xml serializer to deserialize to GetCRResponse beceause of the attributes SOAP-ENC:arrayType that need to be interpreted by the soap serializer.</p>