Quantcast
Channel: WCF, ASMX and other Web Services
Viewing all articles
Browse latest Browse all 555

The remote certificate is invalid according to the validation procedure

$
0
0

I am trying to send post request to a soap web service with basic authentication, i am getting this error "The remote certificate is invalid according to the validation procedure"
When i am testing with SOAPUI  it is working fine..


public static void CallWebService()
{
var _url = "url";
var _action = "action";

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(@"<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""><SOAP-ENV:Header><AUTHHEADER xmlns=""http://tempuri.org/""><USERNAME>xxx</USERNAME><PASSWORD>xxxxx</PASSWORD></AUTHHEADER></SOAP-ENV:Header><SOAP-ENV:Body><inv:H'><inv:h> <inv:Header> <inv:CreationDateTime>2019-06-17</inv:CreationDateTime> <inv:SONO>1</inv:SONO> <inv:POID>1</inv:POID> <inv:GrossWeight>1</inv:GrossWeight> <inv:NetWeight>1</inv:NetWeight> <inv:InvoiceNo>1</inv:InvoiceNo> </inv:Header> <!-- from 1 to unbounded --> <inv:Line> <inv:SONO>1</inv:SONO> <inv:POID>1</inv:POID> <inv:Materialnumber>1</inv:Materialnumber> <inv:QTY>1</inv:QTY> <inv:Amount>100</inv:Amount> </inv:Line> </inv:I> </inv:I></SOAP-ENV:Body></SOAP-ENV:Envelope>");
return soapEnvelop;
}

private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
{
using (Stream stream = webRequest.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
}

protected void Button1_Click(object sender, EventArgs e)
{
CallWebService();
}


Viewing all articles
Browse latest Browse all 555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>