title: How to deserialize soap response?
body: <p>I'm trying to deserialize following xml to c# object:</p>
  
  <pre><code>&lt;S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;S:Body&gt;
    &lt;ns2:topupResponse xmlns:ns2="http://www.claro.com.hn/esb/ws/topups/" 
   xmlns:ns3="http://www.claro.com.hn/esb/ws/ops/"&gt;
       &lt;result&gt;
          &lt;conversionRate&gt;7.7765&lt;/conversionRate&gt;
          &lt;datetime&gt;2018-01-10T08:33:19.685-06:00&lt;/datetime&gt;
          &lt;distAmount&gt;5.00&lt;/distAmount&gt;
          &lt;msisdn&gt;50279613880&lt;/msisdn&gt;
          &lt;newBalance&gt;38&lt;/newBalance&gt;
          &lt;operAmount&gt;38.882500&lt;/operAmount&gt;
          &lt;responseCode&gt;0&lt;/responseCode&gt;
          &lt;transId&gt;228855&lt;/transId&gt;
       &lt;/result&gt;
    &lt;/ns2:topupResponse&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>I've setup my classes like this:</p>
  
  <pre><code>[XmlRoot("Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
  public class Response
  {
      public ResponseBody Body { get; set; }
  }
  
  public class ResponseBody
  {
      [XmlElement(ElementName = "topupResponse", Namespace = "http://www.claro.com.hn/esb/ws/topups/, http://www.claro.com.hn/esb/ws/ops/")]
      public TopupResponse topupResponse { get; set; }
  }
  
  public class TopupResponse
  {
      public Result result { get; set; }
  }
  
  public class Result
  {
      public string conversionRate { get; set; }
      public string datetime { get; set; }
      public string distAmount { get; set; }
      public string msisdn { get; set; }
      public string newBalance { get; set; }
      public string operAmount { get; set; }
      public string responseCode { get; set; }
      public string transId { get; set; }
  }
  </code></pre>
  
  <p>I'm using following method to deserialize:</p>
  
  <pre><code>  private static object XmlDeserializeFromString(string objectData, Type type)
      {
          objectData = RemoveInvalidXmlCharacters(objectData);//customizeoption if you know the xml you receive wont have any invalid characters you can remove this function
  
          var serializer = new XmlSerializer(type);
          object result;
          using (var reader = new StringReader(objectData))
          {
              result = serializer.Deserialize(reader);
          }
          return result;
      }
  </code></pre>
  
  <p>But I'm not getting result values in my object. It only deserializing upto TopupResonse and that's null. I've tried Google a bit but couldn't find anything concrete. I think, the issue is with the namespaces, not exactly sure. Any help would be really appreciated. </p>