title: How to Submit a SOAP Message to External Web service URL?
body: <p>I am trying to send a SOAP Message to a external Url.
  My Code is as a below.</p>
  
  <pre><code>namespace SeadSOAPMessage
  {
      class Program
      {
          static void Main(string[] args)
          {
              CallWebService();
              Console.ReadLine();
          }
  
  
          public static void CallWebService()
          {
              var _url = "http://www.webservicex.com/globalweather.asmx";
              var _action = "http://www.webservicex.com/globalweather.asmx?op=GetWeather";
  
  
              XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
              HttpWebRequest webRequest = CreateWebRequest(_url, _action);
              InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
  
              // begin async call to web request.
              IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
  
              // suspend this thread until call is complete. You might want to
              // do something usefull here like update your UI.
              asyncResult.AsyncWaitHandle.WaitOne();
  
              // get the response from the completed web request.
              string soapResult;
              using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
              {
                  using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                  {
                      soapResult = rd.ReadToEnd();
                  }
                  Console.Write(soapResult);
              }
          }
  
          private static HttpWebRequest CreateWebRequest(string url, string action)
          {
              HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
              webRequest.Headers.Add("SOAPAction", action);
              webRequest.ContentType = "text/xml;charset=\"utf-8\"";
              webRequest.Accept = "text/xml";
              webRequest.Method = "POST";
              return webRequest;
          }
  
          private static XmlDocument CreateSoapEnvelope()
          {
              XmlDocument soapEnvelop = new XmlDocument();
              soapEnvelop.LoadXml(@"&lt;soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""&gt;&lt;soap:Body&gt;&lt;GetWeather xmlns=""http://www.webserviceX.NET""&gt;&lt;CityName&gt;string&lt;/CityName&gt;&lt;CountryName&gt;string&lt;/CountryName&gt;&lt;/GetWeather&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;");
              return soapEnvelop;
          }
  
          private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
          {
              using (Stream stream = webRequest.GetRequestStream())
              {
                  soapEnvelopeXml.Save(stream);
              }
          }
      }
  }
  </code></pre>
  
  <p>The WSDLs  am using are.
  <a href="http://www.webservicex.com/globalweather.asmx" rel="nofollow noreferrer">wsdl url</a></p>
  
  <p><a href="http://www.webservicex.com/globalweather.asmx?op=GetWeather" rel="nofollow noreferrer">method Url</a>
  After doing all the Proceess here I am getting the exception as</p>
  
  <pre><code>The remote server returned an error: (500) Internal Server Error.
  </code></pre>
  
  <p>and after that if i'll Continue execution then second time I am getting another exceptioni.e </p>
  
  <pre><code>EndGetResponse can only be called once for each asynchronous operation.
  </code></pre>
  
  <p>so,what I am doing wrong?</p>