mohammed sajjad

mohammed sajjad

  • NA
  • 44
  • 563

Web Service Integration

Nov 7 2017 2:55 AM
I have these code to call the service, where i have attached the certificate also. but in response i am getting the error as
 
The request was aborted: Could not create SSL/TLS secure channel.
 
can anyone help me catch the error
 
public static HttpWebRequest req = null;
public static HttpWebResponse res = null;
public static string SendRequest(string RequestXml, string SoapAction, ref string SessionId)
{
string Proxy = "https://ines.margento.com:48728/?wsdl";
//string NetworkUserName = ConfigurationManager.AppSettings["NetworkUserName"];
//string NetworkPassword = ConfigurationManager.AppSettings["NetworkPassword"];
//X509Certificate cert = X509Certificate.CreateFromCertFile("D:/NeqatyWS-20160628_doc_samples_updated/NeqatyWS/Certificates/ServerVerification/NeqatyWS-cert-pem.crt","tralala");
X509Certificate2 cert = new X509Certificate2("D:/NeqatyWS-20160628_doc_samples_updated/NeqatyWS/Certificates/ServerVerification/NeqatyWS-cert.der", "tralala");
bool signout = false;
if (SoapAction.IndexOf("SignOut") != -1)
signout = true;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
req = (HttpWebRequest)System.Net.WebRequest.Create("https://ines.margento.com:48728/?wsdl");
req.Timeout = 600000;
req.Headers.Add("SOAPAction", SoapAction);
req.ContentType = "text/xml; charset=utf-8";
req.KeepAlive = false;
req.Method = "POST";
req.ClientCertificates.Add(cert);
req.ProtocolVersion = HttpVersion.Version10;
req.PreAuthenticate = true;
//we add the SessionId to headers if we received before.
if (!String.IsNullOrEmpty(SessionId))
req.Headers.Add("Cookie", SessionId);
//WebProxy myProxy = new WebProxy(Proxy, true);
//myProxy.Credentials = new NetworkCredential(NetworkUserName, NetworkPassword);
//req.Proxy = myProxy;
Stream reqStr = req.GetRequestStream();
StreamWriter sw = new StreamWriter(reqStr);
sw.Write(RequestXml);
sw.Close();
string strResult = "";
try
{
res = (HttpWebResponse)req.GetResponse();
Stream resStr = res.GetResponseStream();
StreamReader sr = new StreamReader(resStr);
strResult = sr.ReadToEnd();
sr.Close();
//Receive the SessionId from Headers.
if (!String.IsNullOrEmpty(res.Headers["Set-Cookie"]))
SessionId = res.Headers["Set-Cookie"];
res.Close();
}
catch (WebException ex)
{
string errMessage = ex.Message;
strResult = errMessage;
if (ex.Response != null)
{
System.IO.Stream resStr = ex.Response.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(resStr);
string soapResponse = sr.ReadToEnd();
sr.Close();
resStr.Close();
errMessage += Environment.NewLine + soapResponse;
strResult = errMessage;
ex.Response.Close();
}
}
if (signout)
SessionId = "";
return strResult;
}
}

Answers (1)