How do I allow my web service to work with a Proxy Server

We are developing an application that has a client application that needs to call a web service that is located on our web server.  The client application will be install by a wide range of users spanning from home users to people behind corporate firewalls.

What functionality do we need in our product to ensure that we can work with different proxy servers.  I see that application like Instant messenger and Norton Antivirus allow for proxy setting to be supplied by the user& I have read about using default proxy and cached credentials.

Dim proxy As System.Net.WebProxy = System.Net.WebProxy.GetDefaultProxy
proxy.Credentials = System.Net.CredentialCache.DefaultCredentials
ws.Proxy = proxy

I am having trouble understanding what should be included in our client application, what are different techniques to do the same thing.

So the question&
I am looking for a sample application that shows/describes the best practices of implementing web services to work with proxy servers.  I would like to understand why applications like Norton Antivirus have the options to specify proxy settings.
Who is Participating?
jinalConnect With a Mentor Commented:
Hello ,
In some of the case you need to supply credentials for proxy server to.
ws.Proxy.Credentials = ....


Use configuration file.
This is sample
    <proxy usesystemdefault="true" />

Also in your sample  you did use System.Net.WebProxy.GetDefaultProxy which is deprecated .
jongrossexAuthor Commented:

Hi Jinal,

Thanks for your comments.

I have tried to put together a sample based on what I have read.  Please critique the sample code.  I am interested if I am close or how to make it better.

Do you have any special error handling that you use when calling a web service?

Private Sub cmdGetPatientName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetPatientName.Click
    Dim bUserSuppliedNetworkCredentails As Boolean = True
    'Call a function to see if the user want to specify credentials
    Dim bUserSuppliedProxyInfo As Boolean = True
    'Call a function to see if the user has given us proxy information
    Dim ws As New SampleWebService.Service1
    If bUserSuppliedProxyInfo Then
      ws.Proxy = New System.Net.WebProxy("http://myWebProxy", 456)
      ws.Proxy = System.Net.WebRequest.DefaultWebProxy
    End If
    If bUserSuppliedNetworkCredentails Then
      ws.Credentials = New NetworkCredential("UserName", "Password", "Domain")
    End If
    Dim patientId As Integer = 123
    Dim patientName As String = ws.GetPatientName(patientId)
    MsgBox(patientName, MsgBoxStyle.Information)
  End Sub

Open in new window

jongrossexAuthor Commented:
Thanks for your help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.