title: Send xml with a post request to wcf service on iis
body: <p>SOLVED with <a href="https://programmingistheway.wordpress.com/2015/07/08/sending-xml-to-a-wcf-restful-service/" rel="nofollow noreferrer">this link</a></p>
  
  <p>I'm developing a wcf service, with rest pattern. Now it is on a IIS server.</p>
  
  <p>It has got a method callable with a post, which has to receive a xml data.</p>
  
  <p>I'm trying to send this xml (with other parameter), but I'm getting only deserial errors:</p>
  
  <pre><code>in System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)
  
  in System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters)
  
  in System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters)
  
  in System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc&amp;amp; rpc)
  
  in System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;amp; rpc)
  
  in System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp;amp; rpc)
  
  in System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp;amp; rpc)
  
  in System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
  </code></pre>
  
  <p>This is the request: </p>
  
  <pre><code>retista=0019&amp;hashedStrig=dkfjdkfjd&amp;dati=&lt;ArrayOfWrapClienti xmlns="http://schemas.datacontract.org/2004/07/MultipayOnline" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;&lt;WrapClienti&gt;&lt;CODRETE&gt;0018&lt;/CODRETE&gt;&lt;CODICE&gt;20685&lt;/CODICE&gt;&lt;NOME&gt;A.T.E.R. Azienda Territoriale&lt;/NOME&gt;&lt;INDIRIZZO&gt;PIAZZA POZZA&lt;/INDIRIZZO&gt;&lt;CITTA&gt;Verona&lt;/CITTA&gt;&lt;CAP&gt;37123&lt;/CAP&gt;&lt;PROV&gt;VR&lt;/PROV&gt;&lt;CODICEFISCALE&gt;00223640236&lt;/CODICEFISCALE&gt;&lt;PIVA&gt;223640236&lt;/PIVA&gt;&lt;EMAIL/&gt;&lt;ESPOSIZ_CONTABILE&gt;937,02&lt;/ESPOSIZ_CONTABILE&gt;&lt;STATO&gt;FALSE&lt;/STATO&gt;&lt;/WrapClienti&gt;&lt;/ArrayOfWrapClienti&gt;
  </code></pre>
  
  <p>and this is the xml I'm trying to send:</p>
  
  <pre><code>&lt;ArrayOfWrapClienti xmlns="http://schemas.datacontract.org/2004/07/aaa" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;WrapClienti&gt;
  &lt;CODRETE&gt;1111&lt;/CODRETE&gt;
  &lt;CODICE&gt;111&lt;/CODICE&gt;
  &lt;NOME&gt;AAA&lt;/NOME&gt;
  &lt;INDIRIZZO&gt;PIAZZA&lt;/INDIRIZZO&gt;
  &lt;CITTA&gt;AAA&lt;/CITTA&gt;
  &lt;CAP&gt;111&lt;/CAP&gt;
  &lt;PROV&gt;aa&lt;/PROV&gt;
  &lt;CODICEFISCALE&gt;111&lt;/CODICEFISCALE&gt;
  &lt;PIVA&gt;223611140236&lt;/PIVA&gt;
  &lt;EMAIL/&gt;
  &lt;ESPOSIZ_CONTABILE&gt;1111&lt;/ESPOSIZ_CONTABILE&gt;
  &lt;STATO&gt;FALSE&lt;/STATO&gt;
  &lt;/WrapClienti&gt;
  &lt;/ArrayOfWrapClienti&gt;
  </code></pre>
  
  <p>If you click <a href="http://37.59.146.241:8096/MultiPOService.svc/cliente.xml?retista=0018&amp;cliente=CLI0001&amp;H=qA9Myu9aOP7jiZ7VddiUMg==" rel="nofollow noreferrer">here</a>, you can find out how an xml is returned by my wcf. I thought I have to send the same xml with other data, but I get the deserial error. </p>
  
  <p>Why?</p>
  
  <p>How can I send the xml to my wcf? In this test phase, I'm using <a href="https://www.hurl.it/" rel="nofollow noreferrer">this</a>.</p>
  
  <p>If I can give to you other useful infos, ask me and I'll write them here.</p>
  
  <p><strong>UPDATE</strong>: The text of the error message says that there are invalid data at root level, row 1, pos 1. Also if I put</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  </code></pre>
  
  <p>at the root level.</p>
  
  <p><strong><em>Maybe are there some missing headers?</em></strong></p>
  
  <p><strong>UPDATE server side</strong>: </p>
  
  <p>this is how my server wcf is configured:</p>
  
  <pre><code>    [OperationContract]
      [WebGet(UriTemplate = "cliente.xml?retista={codret}&amp;cliente={codiceCliente}&amp;H={hashedString}", ResponseFormat = WebMessageFormat.Xml)]
      List&lt;WrapClienti&gt; GetClienteXML(string codret, string codiceCliente, string hashedString);
  </code></pre>
  
  <p>and this is the called method:</p>
  
  <pre><code>    public GenericResponse SetClientiXML(List&lt;WrapClienti&gt; clienti, string retista, string hashedString) 
      {
          var api = new API();
          return api.SetClienti(clienti, retista, hashedString);        
      }
  </code></pre>
  
  <p>as you can I see, I don't manage any xml/json deserialzing phase, it is managed by the wcf routine. For example, if I send a json list, it converts it to a List. This is what also with xml I want to see, but I'm getting the error at the top of this question.</p>
  
  <p>ANOTHER UPDATE: I have to send 3 parameters in xml, so.... this is my last attempt, I think it is more correct than previouses. Now the server gives null reference error:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;SetClientiXML
    xmlns="http://tempuri.org/"&gt;
    &lt;XMLRequest&gt;
      &lt;ArrayOfWrapClienti
        xmlns="http://schemas.datacontract.org/2004/07/aaa"
        xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
        &lt;WrapClienti&gt;
          &lt;CODRETE&gt;111&lt;/CODRETE&gt;
          &lt;CODICE&gt;111&lt;/CODICE&gt;
          &lt;NOME&gt;aaa&lt;/NOME&gt;
          &lt;INDIRIZZO&gt;aaa&lt;/INDIRIZZO&gt;
          &lt;CITTA&gt;aaa&lt;/CITTA&gt;
          &lt;CAP&gt;aaa&lt;/CAP&gt;
          &lt;PROV&gt;aa&lt;/PROV&gt;
          &lt;CODICEFISCALE&gt;111&lt;/CODICEFISCALE&gt;
          &lt;PIVA&gt;2236401111236&lt;/PIVA&gt;
          &lt;EMAIL/&gt;
          &lt;ESPOSIZ_CONTABILE&gt;111&lt;/ESPOSIZ_CONTABILE&gt;
          &lt;STATO&gt;FALSE&lt;/STATO&gt;
        &lt;/WrapClienti&gt;
      &lt;/ArrayOfWrapClienti&gt;
      &lt;RETISTA&gt;1111&lt;/RETISTA&gt;
      &lt;HASHEDSTRING&gt;oklkokokokok&lt;/HASHEDSTRING&gt;
    &lt;/XMLRequest&gt;
  &lt;/SetClientiXML&gt;
  </code></pre>
  
  <p>I have also created this class:</p>
  
  <pre><code>[DataContract]
  public class XMLRequest
  {
      [DataMember]
      public List&lt;WrapClienti&gt; XML;
      [DataMember]
      public string RETISTA;
      [DataMember]
      public string HASHEDSTRING;
      public XMLRequest() { }
      public XMLRequest(List&lt;WrapClienti&gt; x, string r, string h)
      {
          this.HASHEDSTRING = h;
          this.XML = x;
          this.RETISTA = r;
      }
  }
  </code></pre>
  
  <p>and the portotype now is:</p>
  
  <pre><code>public GenericResponse SetClientiXML(XMLRequest xr)
  </code></pre>