title: Parse Soap XML into Object in C#
body: <p>I have the following SOAP XML</p>
  
  <pre><code>string soap = "&lt;soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns='http://schemas.abudhabi.ae/sso/2010/11'&gt;" +
     "&lt;soapenv:Header/&gt;" +
     "&lt;soapenv:Body&gt;" +
        "&lt;ns:GetUserProfileResponse&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:userid&gt;?&lt;/ns:userid&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:firstNameAr&gt;?&lt;/ns:firstNameAr&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:firstNameEn&gt;?&lt;/ns:firstNameEn&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:middleNameAr&gt;?&lt;/ns:middleNameAr&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:middleNameEn&gt;?&lt;/ns:middleNameEn&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:thirdNameAr&gt;?&lt;/ns:thirdNameAr&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:thirdNameEn&gt;?&lt;/ns:thirdNameEn&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:fourthNameAr&gt;?&lt;/ns:fourthNameAr&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:fourthNameEn&gt;?&lt;/ns:fourthNameEn&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:familyNameAr&gt;?&lt;/ns:familyNameAr&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:familyNameEn&gt;?&lt;/ns:familyNameEn&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:authLevel&gt;?&lt;/ns:authLevel&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:dateOfBirth&gt;?&lt;/ns:dateOfBirth&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:gender&gt;?&lt;/ns:gender&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:nationalityCode&gt;?&lt;/ns:nationalityCode&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:idn&gt;?&lt;/ns:idn&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:modifyTimestamp&gt;?&lt;/ns:modifyTimestamp&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:prefComChannel&gt;?&lt;/ns:prefComChannel&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:secretQuestionAnswer&gt;?&lt;/ns:secretQuestionAnswer&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:secretQuestionId&gt;?&lt;/ns:secretQuestionId&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:address&gt;" +
              "&lt;!--Optional:--&gt;" +
              "&lt;ns:additionalAddressInfo&gt;?&lt;/ns:additionalAddressInfo&gt;" +
              "&lt;!--Optional:--&gt;" +
              "&lt;ns:city&gt;?&lt;/ns:city&gt;" +
              "&lt;!--Optional:--&gt;" +
              "&lt;ns:fax&gt;?&lt;/ns:fax&gt;" +
              "&lt;!--Optional:--&gt;" +
              "&lt;ns:residenceCountry&gt;?&lt;/ns:residenceCountry&gt;" +
              "&lt;!--Optional:--&gt;" +
              "&lt;ns:poBox&gt;?&lt;/ns:poBox&gt;" +
              "&lt;!--Optional:--&gt;" +
              "&lt;ns:stateOrEmirate&gt;?&lt;/ns:stateOrEmirate&gt;" +
              "&lt;!--Optional:--&gt;" +
              "&lt;ns:streetNameAndNumber&gt;?&lt;/ns:streetNameAndNumber&gt;" +
              "&lt;!--Optional:--&gt;" +
              "&lt;ns:zipCode&gt;?&lt;/ns:zipCode&gt;" +
           "&lt;/ns:address&gt;" +
           "&lt;!--Optional:--&gt;" +
           "&lt;ns:contact&gt;" +
              "&lt;!--Optional:--&gt;" +
              "&lt;ns:email&gt;?&lt;/ns:email&gt;" +
              "&lt;!--Optional:--&gt;" +
              "&lt;ns:mobilePhoneNumber&gt;?&lt;/ns:mobilePhoneNumber&gt;" +
              "&lt;!--Optional:--&gt;" +
              "&lt;ns:website&gt;?&lt;/ns:website&gt;" +
              "&lt;!--Optional:--&gt;" +
              "&lt;ns:workPhone&gt;?&lt;/ns:workPhone&gt;" +
           "&lt;/ns:contact&gt;" +
        "&lt;/ns:GetUserProfileResponse&gt;" +
     "&lt;/soapenv:Body&gt;" +
  "&lt;/soapenv:Envelope&gt;";
  </code></pre>
  
  <p>I wanted it to Parse or Convert into following Class</p>
  
  <pre><code>public class UserProfile
          {
              public string FirstNameAR { get; set; }
  
              public string FirstNameEN { get; set; }
  
              public string MiddleNameAR { get; set; }
  
              public string MiddleNameEN { get; set; }
  
              public string ThirdNameAR { get; set; }
              public string ThirdNameEN { get; set; }
  
  
              public string FourthNameAR { get; set; }
  
              public string FourthNameEN { get; set; }
  
              public string FamilyNameAR { get; set; }
  
              public string FamilyNameEN { get; set; }
  
              public Boolean AuthLevelSpecified { get; set; }
  
              public DateTime DateOfBirth { get; set; }
              public bool DateOfBirthSpecified { get; set; }
  
  
              public Boolean GenderTypeSpecified { get; set; }
  
              public string NationalityCode { get; set; }
  
              public string IDN { get; set; }
  
              public Boolean ModifyTimeStampSpecified { get; set; }
              public DateTime ModifyTimeStamp { get; set; }
  
              //  public PrefComChannelType PrefComChannelType { get; set; }
              public Boolean PrefComChannelTypeSpecified { get; set; }
  
              public string SecretQuestion { get; set; }
  
              public int SecretQuestionId { get; set; }
  
              public Boolean SecretQuestionSpecified { get; set; }
             }
  </code></pre>
  
  <p>and my code is :</p>
  
  <pre><code>var Value = XDocument.Parse(soap);
  
  XNamespace ns = @"http://schemas.xmlsoap.org/soap/envelope/";
   var unwrappedResponse = Value.Descendants((XNamespace)"http://schemas.xmlsoap.org/soap/envelope/" + "Body").First().FirstNode;
  
   XmlSerializer oXmlSerializer = new XmlSerializer(typeof(UserProfile));
  
   var responseObj = (UserProfile)oXmlSerializer.Deserialize(unwrappedResponse.CreateReader());
  </code></pre>
  
  <p>I am following this question <a href="https://stackoverflow.com/questions/20270314/removing-extracting-soap-header-and-body-from-soap-message">removing/extracting soap header and body from soap message</a>
  But I am getting error.Is there any thing wrong with this Code.Please Help</p>