How do I access a Web Service through a Proxy Server?

less than 1 minute to read

The Web Service Proxy Generator by default uses the system proxy settings. Typically these settings are the same settings that are configured for the proxy in Internet Explorer which effectively mimics the system settings.

You can override Http Proxy settings in several ways.

.config File overrides

One of the easiest ways to override configuration settings is via a config file setting that .NET recognizes. You can simply add the following into yourapplication.exe.config and/or vfp9.exe.config:

xml
<configuration> <defaultProxy> <proxy proxyaddress="http://127.0.0.1:8888" /> </defaultProxy> </system.net> </configuration>

Explicitly setting Http Proxy Settings in Code

You can explicitly override the proxy settings via code using Proxy property of the native .NET service object (loProxy.oService.Proxy). The following example demonstrates:

foxpro
DO WebStoreServiceProxy LOCAL loProxy as WebStoreSerivceProxy loProxy = CREATEOBJECT("WebStoreServiceProxy") loBridge = loProxy.oBridge *** Create the Http Proxy instance and point at Host and Port loWebProxy = loBridge.CreateInstance("System.Net.WebProxy","127.0.0.1",8888) *** Optionally create credentials for the proxy loWebProxy.Credentials = loBridge.CreateInstance("System.Net.NetworkCredential","rstrahl","wwind") *** Assign the Http Proxy to the .NET instance loProxy.oService.Proxy = loWebProxy loItem = loProxy.DownloadInventoryItem("WCONNECT50") ? loItem

The key here is:

foxpro
loService.Proxy = loBridge.CreateInstance("System.Net.WebProxy","127.0.0.1",8888)

which creates an instance of the WebProxy object. Once you have the Http Proxy you can also assign a user name and password as shown in the longer example above. Do this only if your proxy requires authentication for browsing (which is rare these days).


© West Wind Technologies, 2004-2020 • Updated: 09/29/15
Comment or report problem with topic