Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Re: Calling a webservice over ssl from an aspx page.


Message #1 by "Goh Mingkun" <mangokun@h...> on Thu, 21 Feb 2002 04:02:02
I have got a sample Windows Application that retrieve an icon on an remote 
(Internet) web server.
--------------------------------------------------
Dim HttpWReq As HttpWebRequest = CType(WebRequest.Create
("http://sg.geocities.com/mangokun/images/settings.ico"), HttpWebRequest)
        ' Turn off connection keep-alives.
        HttpWReq.KeepAlive = False

	' Use only if needed
        'HttpWReq.Proxy = New WebProxy("http://proxyname:80/")

        Dim HttpWResp As HttpWebResponse = CType(HttpWReq.GetResponse(), 
HttpWebResponse)

        Dim imgstream As System.IO.Stream= HttpWResp.GetResponseStream()
        Dim img As Image= Image.FromStream(imgstream)
        HttpWResp.Close()

        TextBox1.Text = HttpWResp.ResponseUri.ToString
        txtimgName.Text = Path.GetFileName(HttpWResp.ResponseUri.ToString)
        txtimgDimension.Text = img.PhysicalDimension.ToString
        PictureBox1.Image = img
--------------------------------------------------

If you might have noticed, I have commented out the line: HttpWReq.Proxy = 
New WebProxy("http://proxyname:80/"), because the proxy is either not 
needed, or it auto-detected the proxy.

When calling a webservice from an ASP.NET page, maybe you need to set the 
proxy of the Web Service instance before calling any of its method.

Here is an example:
Dim ws As New wsDic.arabicdictionary()
ws.Proxy = New WebProxy("http://yourproxynamehere:80/") 'maybe required
result = ws.GetEEMeaning("clever")

-----
Let me explain a bit on proxy:
In a Windows Application, proxy will be auto-detected when you call a 
remote web service method (outside your Intranet).
But for Web Applications and Web Services, this may not be the case.
Therefore you have to explicitly set the proxy setting for the accessing 
object.




> I am unable to call a webservice from an aspx page using SSL.  If I 
> call the asmx file from Internet Explorer 6 I can make a secure 
connection 
> to the webservice and invoke the methods without any problem.
> 
> However,  If I add the web reference to an ASP.NET project (making sure 
to 
> specify https when I add the reference) I get the following error when I 
> call any webmethod on the webservice:
> 
> The underlying connection was closed: Could not establish trust 
> relationship with remote server. 
> 
> So what is IE 6 doing that allows it to connect to the webservice that 
> ASP.NET doesn't do.  Is there some function I need to call or property I 
> need to set?
> 
> I found an example that used WebRequest and tried that.  I still got the 
> same error.  The documentation stated that WebRequest will automatically 
> use SSL when used with https. I am assuming, (perhaps wrongly) that the 
> proxy generated on the https connection should work automatically as 
well.
> 
> I also looked on GOOGLE, it looks like other people are also having this 
> problem.  I tried some of the suggestions that I found there but they 
did 
> not resolve the problem.
> 
> I have tried adding the CA to the ClientCertificate collection on the 
> proxy generated for the webservice to no avail.
> 
> Any suggestions, samples or white papers on this subject would be 
greatly 
> appreciated.
> 
> Thanks,
> 
> Chris Post

  Return to Index