Discussion:
WebProxy Error "Unable to cast WebProxyWrapper to System.Net.WebPr
(too old to reply)
Phil
2007-02-06 10:33:01 UTC
Permalink
I am connecting to a webservice via http but some of our clients use a proxy
server.

The following code worked fine in .Net 1.1 but fails in .Net 2 with the
following error on the line objHTTP.Proxy = objProxy

"Unable to cast object pf type WebProxyWrapper to type System.Net.WebProxy"

The documents say this the correct way and syntax for .Net 2.

Dim objHTTP As HttpWebRequest = CType(WebRequest.Create(objSettings.URL),
HttpWebRequest)
Dim objProxy As System.Net.WebProxy = Nothing
Dim objUri As System.Uri = Nothing
objProxy = New System.Net.WebProxy
objProxy = CType(objHTTP.Proxy, WebProxy)
objUri = New System.Uri("http:\\ProxyIP")
objProxy.Address = objUri
objProxy.Credentials = System.Net.CredentialCache.DefaultCredentials
objHTTP.Proxy = objProxy

Any ideas?
Phil
2007-02-08 09:31:00 UTC
Permalink
This has been resolved now. Microsoft response as follows...

Because of redesign of WebProxy object and interface with extra added
feature for autoproxy handling in framework 2.0. HttpWebRequest.Proxy object
don't need to be converted or cast into WebProxy object. HttpWebRequest.Proxy
is declared as Interface for IWebProxy, which is the base class of WebProxy
class. So it needs to be assigned with a WebProxy object directly without
casting.

The code will look like this:

Dim objHTTP As HttpWebRequest =
CType(WebRequest.Create("http://MyWebSite"), HttpWebRequest)
objHTTP.Proxy = New System.Net.WebProxy("http:\\MyProxyServer", True)
'true is bypass the proxy for local address
objHTTP.Proxy.Credentials =
System.Net.CredentialCache.DefaultCredentials
objHTTP.Credentials = System.Net.CredentialCache.DefaultCredentials
Post by Phil
I am connecting to a webservice via http but some of our clients use a proxy
server.
The following code worked fine in .Net 1.1 but fails in .Net 2 with the
following error on the line objHTTP.Proxy = objProxy
"Unable to cast object pf type WebProxyWrapper to type System.Net.WebProxy"
The documents say this the correct way and syntax for .Net 2.
Dim objHTTP As HttpWebRequest = CType(WebRequest.Create(objSettings.URL),
HttpWebRequest)
Dim objProxy As System.Net.WebProxy = Nothing
Dim objUri As System.Uri = Nothing
objProxy = New System.Net.WebProxy
objProxy = CType(objHTTP.Proxy, WebProxy)
objUri = New System.Uri("http:\\ProxyIP")
objProxy.Address = objUri
objProxy.Credentials = System.Net.CredentialCache.DefaultCredentials
objHTTP.Proxy = objProxy
Any ideas?
Loading...