Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to access Secure Web Site using WINHTTP

Status
Not open for further replies.

nomi2000

ISP
Feb 15, 2001
676
CA
Hi guys i wrote down the following code to connect to a secure web site using WINHTTP,but i am getting "security error",although i can access some other websites with this code but when i am trying to connect to Secure Web Site with the client certificate i am getting the above error..
Thanks
Nouman

ERROR
=====
System.Runtime.InteropServices.COMException (0x80072F8F): A security error occurred
at WinHttp.WinHttpRequestClass.Send(Object Body)
at SOAPWebApp.WebForm1.btnTest_Click(Object sender, EventArgs e) in C:\Inetpub\ 118

CODE
====
Try
Dim sss As String = ""
Dim HttpReq As New WinHttp.WinHttpRequest
' Open an HTTP connection.
HttpReq.Open("PUT", " False)
If Trim(txtUsername.Text) <> "" And Trim(txtPassword.Text) <> "" Then
HttpReq.SetCredentials(Trim(txtUsername.Text), Trim(txtPassword.Text), 0)
End If
' Select the client certificate.
HttpReq.Option(WinHttp.WinHttpRequestOption.WinHttpRequestOption_SelectCertificate) = "LOCAL_MACHINE\My\Joe's-Software-Emporium"
HttpReq.SetClientCertificate("LOCAL_MACHINE\My\Joe's-Software-Emporium")
' Set Header for SOAP Action
HttpReq.SetRequestHeader("SOAPAction", " HttpReq.SetRequestHeader("Content-Type", "text/xml; charset=utf-8") 'FOR SOAP
HttpReq.SetRequestHeader("Content-Length", Len(sss))
' Send the HTTP Request.
HttpReq.Send()
TextBox1.Text = HttpReq.ResponseText
Catch exp As Exception
TextBox1.Text = "Error Occurred : " & exp.Message & vbCrLf & vbCrLf & exp.GetBaseException.ToString
End Try


Nouman Zaheer
Software Engineer
MSR
 
Out of curiosity, why aren't you using .NET's snazzy powerful Web Services features?
 
HI thanks for your response but How i will do this ?
Regards
Nouman

Nouman Zaheer
Software Engineer
MSR
 
If you're consuming someone else's Web Service, you may do the following:

1. In the designer, right-click your project and select "Add Web Reference".

2. Enter the URL of the service you want to consume. The dialog should display information about the available services if all goes well.

3. Select the service you want and OK your way out of the dialogs (or whatever).

VS.NET will then create proxy classes to handle all of the plumbing for the Web Services. Once you reach this point, you can instantiate the Service as an object, and treat it like you would any other class (making method calls, getting return values, etc). Microsoft made it pretty user friendly!

This tutorial will explain more:

 
Hi boulderBam
You see what i want is not that much easy i know how i can call a web-service at the Net but my problem is that the web-site i am trying to connect is a JAVA refferer so i need to submit packet of information to that site with a client certificate used for authentication with the above code i can hit some other web-sites which is non-secure but when i am trying to connect to the secure web-site its giving me that error.
Regarda
Nouman


Nouman Zaheer
Software Engineer
MSR
 
Could it be as simple as the account the cope runs under not having access to the certificate on the local machine?

Greetings,
Dragonwell
 
Try



Dim sss As String = ""

Dim HttpReq As New WinHttp.WinHttpRequest



' Open an HTTP connection.



HttpReq.Open("PUT", " False)



If Trim(txtUsername.Text) <> "" And Trim(txtPassword.Text) <> "" Then

HttpReq.SetCredentials(Trim(txtUsername.Text), Trim(txtPassword.Text), 0)

End If

''Select a client certificate.

HttpReq.Option(WinHttp.WinHttpRequestOption.WinHttpRequestOption_SelectCertificate) = "LOCAL_MACHINE\My\Joe's-Software-Emporium"

HttpReq.SetClientCertificate("LOCAL_MACHINE\My\Joe's-Software-Emporium")



''Set Header for SOAP Action

HttpReq.SetRequestHeader("SOAPAction", "
HttpReq.SetRequestHeader("Content-Type", "text/xml; charset=utf-8") 'FOR SOAP

HttpReq.SetRequestHeader("Content-Length", Len(sss))

' Send the HTTP Request.

HttpReq.Send()

TextBox1.Text = HttpReq.ResponseText







Catch exp As Exception

TextBox1.Text = "Error Occurred : " & exp.Message & vbCrLf & vbCrLf & exp.GetBaseException.ToString

End Try


ERROR I AM GETTING

Error Occurred : A security error occurred





System.Runtime.InteropServices.COMException (0x80072F8F): A security error occurred



at WinHttp.WinHttpRequestClass.Send(Object Body)

at SOAPWebApp.WebForm1.btnTest_Click(Object sender, EventArgs e) in C:\Inetpub\ 118




Nouman Zaheer
Software Engineer
MSR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top