Last post Aug 27, 2015 05:55 AM by Zhi Lv - MSFT
Aug 25, 2015 06:16 PM|hadjims|LINK
Hope this is the right forum to post my question. I've been searching the last week how to send an xml request to a third party web service which certifications are involved.
My client need to send some data to another site, and the other company suggested to do this through their web service. They provided me with the documentation, some certifications, a .p12, a .pem and .jks file. They also send me the password for these certificates.
First I install the certificate using the .p12 file but I was not able to access their web service. A message was thrown 403, Forbidden. After searching the net, I found an article suggesting the code below. So I tried that but, no luck. I receive the same
exception every time I'm trying to get a response.
Dim req As HttpWebRequest
req = HttpWebRequest.Create("service url"))
req.Method = "POST"
req.ContentType = "application/xml"
req.Accept = "application/xml"
Dim cert As X509Certificates.X509Certificate2
cert = New X509Certificates.X509Certificate2("c:\tmp\cert.p12", "password")
System.Net.ServicePointManager.CertificatePolicy = New TrustAllCertificatePolicy()
Dim dataToPost As String = File.ReadAllText("C:\tmp\data.xml")
Dim writer As New StreamWriter(req.GetRequestStream())
Dim rsp As HttpWebResponse = req.GetResponse()
Dim reader As New System.IO.StreamReader(rsp.GetResponseStream())
Dim retData As String = reader.ReadToEnd()
This the first time I'm calling a web service with certificate. Another thing, is that I cannot add the web service as service reference in my .net project. The same exception is given.
Thanks in advanced
Aug 27, 2015 05:55 AM|Zhi Lv - MSFT|LINK
As for the 403 Forbidden error, I suggest you could grant the Read permission to the account of the authenticated user for the file that you want to use. To do this, follow these steps:
If it is still not working, I suggst you could post this issue to IIS forum, the following is the IIS forum address:
Besides, here are some relevant articles about calling a Web Service Using Client Certificates, please refer to them: