title: Using Httpclient for send SOAP request In Asp.net Core
body: <p>Im using  Asp.net Core, for calling an <code>asmx service</code> which has 4 methods and i want to call one of them by the name: <code>Verify</code> method, i do this steps:</p>
  
  <p>1-Create realted <code>SOAP</code>:</p>
  
  <pre><code>     private XmlDocument CreateSoapEnvelope(PayVM  payModel)
       {
              XmlDocument soapEnvelop = new XmlDocument();
              string requiredXML = string.Format(@"&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/1999/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/1999/XMLSchema""&gt;&lt;SOAP-ENV:Body&gt;&lt;verifyTransaction xmlns=""http://tempuri.org/""&gt; &lt;String_1 xsi:type=""xsd:string""&gt;{0}&lt;/String_1&gt;&lt;String_2 xsi:type=""xsd:string""&gt;{1}&lt;/String_2&gt;&lt;/verifyTransaction&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt;", payModel.ReNO, payModel.MID);
              soapEnvelop.LoadXml(requiredXML);
              return soapEnvelop;
       }
  </code></pre>
  
  <p>2-create the <code>HttpClient</code> and send my request:</p>
  
  <pre><code>            XmlDocument soapRequest = CreateSoapEnvelope(iPGVerifyResultModel);
              using (var client = new HttpClient())
              {
                  var request = new HttpRequestMessage()
                  {
                      RequestUri = new Uri("relatedUri/ServiceName.asmx"),
                      Method = HttpMethod.Post
                  };
  
                  request.Content = new StringContent(soapRequest.ToString(), Encoding.UTF8, "text/xml");
  
                  request.Headers.Clear();
                  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));
                  request.Content.Headers.ContentType = new MediaTypeHeaderValue("text/xml");
                  request.Headers.Add("SOAPAction", "Verify"); //I want to call this method 
  
                  HttpResponseMessage response = client.SendAsync(request).Result;
  
                  if (!response.IsSuccessStatusCode)
                  {
                      throw new Exception();
                  }
  
                  Task&lt;Stream&gt; streamTask = response.Content.ReadAsStreamAsync();
                  Stream stream = streamTask.Result;
                  var sr = new StreamReader(stream);
                  var soapResponse = XDocument.Load(sr);
                 //do some other stuff...
              }
  </code></pre>
  
  <p>but i didn't result, i try uses service by same parameters with <code>Soap UI</code> and the service work properly, but in my way i got <code>StatusCode: 400</code> what is the problem?</p>