Click here to Skip to main content
15,741,818 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can Any One Help me It Will Return "Unable to connect to the remote server"

C#
 string soap =
 @"<?xml version=""1.0"" encoding=""utf-8""?>
<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/"">
  <soap:Body>
    <Register xmlns=""http://tempuri.org/"">
      <id>123</id>
      <data1>string</data1>
    </Register>
  </soap:Body>
</soap:Envelope>";

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://203.199.22.139/testlink/OnlineProducts/anhWs/service.asmx");
        req.Headers.Add("SOAPAction", "\"http://tempuri.org/InsuranceDetails\"");
        req.ContentType = "text/xml;charset=\"utf-8\"";
        req.Accept = "text/xml";
        req.Method = "POST";

        using (Stream stm = req.GetRequestStream())
        {
            using (StreamWriter stmw = new StreamWriter(stm))
            {
                stmw.Write(soap);
            }
        }
        string soapResult;
        WebResponse response = req.GetResponse();

        using (StreamReader rd = new StreamReader(response.GetResponseStream()))
        {
            soapResult = rd.ReadToEnd();
        }
        Console.Write(soapResult);
Posted
Comments
ZurdoDev 10-Sep-13 7:54am    
Make sure the url is right. See if there is an innnerexception with more information.

1 solution

I will suggest first check is that URL is accessible in browser. If so please check whether it will required secure call, I mean by using Https if so then please add following code
C#
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(
                    delegate(object sender2, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
                    {
                        return true;
                    });
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900