Click here to Skip to main content
6,293,171 members and growing! (11,976 online)
Email Password   helpLost your password?
Web Development » Web Services » General     Intermediate

Connect to a web service through a Proxy Server

By Bruno Capuano

Connect to a web service through a Proxy Server
VB, Windows, .NET 1.0, .NET 1.1, Visual Studio, Dev
Posted:29 Jun 2003
Views:222,000
Bookmarked:49 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
18 votes for this article.
Popularity: 5.69 Rating: 4.53 out of 5

1

2
2 votes, 11.1%
3
1 vote, 5.6%
4
15 votes, 83.3%
5

Introduction

This article explains the how you access a webservice through a Proxy Server.

Using the code

In order to show an example of this, we will use a public web service provided by Google. To use this ws, we need to obtain a Validation Key from Google. Next we defined the search criteria and we display the total of obtained registries.

We use the following libraries :

NetworkCredential Class

Provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication. For a list of all members of this type, see NetworkCredential Members. The NetworkCredential class is a base class that supplies credentials in password-based authentication schemes such as basic, digest, NTLM, and Kerberos. Classes that implement the ICredentials interface, such as the CredentialCache class, return NetworkCredential instances. This class does not support public key-based authentication methods such as SSL client authentication.

WebProxy Class

Contains HTTP proxy settings for the WebRequest class. For a list of all members of this type, see WebProxy Members. The WebProxy class contains the proxy settings that WebRequest instances use to override the proxy settings in GlobalProxySelection. The WebProxy class is the base implementation of the IWebProxyinterface.

The Proxy Server IP Adress is 127,0,1,2 and the port is the 80. 
The data of the user for the authentication with the proxy are: 
User Id: user 
Password: pwd 
Domain: MyDomain 

The following VB.NET code shows an example:

' Search button: do a search, display number of results 

Private Sub btnSearch_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles btnSearch.Click 

' Create a Google Search object 

Dim s As New Google.GoogleSearchService 

Try 

' google params 

Dim strLicenceseKey As String = "google license key" ' google license key 

Dim strSearchTerm As String = "Bruno Capuano" ' google license key 


' proxy settings 

Dim cr As New System.Net.NetworkCredential("user", "pwd", "MyDomain") 
Dim pr As New System.Net.WebProxy("127.0.1.2", 80) 

pr.Credentials = cr 
s.Proxy = pr 

' google search

Dim r As Google.GoogleSearchResult = s.doGoogleSearch(strLicenceseKey, _
  strSearchTerm, 0, 10, True, "", False, "", "", "")
' Extract the estimated number of results for the search and display it

Dim estResults As Integer = r.estimatedTotalResultsCount 

MsgBox(CStr(estResults))

Catch ex As System.Web.Services.Protocols.SoapException

MsgBox(ex.Message)

End Try

End Sub 

If you want to use the current user credential you can use the DefaultCredentials Property. The DefaultCredentials property applies only to NTLM, negotiate, and Kerberos-based authentication. Sample :

' set default credentials

pr.Credentials = System.Net.CredentialCache.DefaultCredentials 

DefaultCredentials represents the system credentials for the current security context in which the application is running. For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application. For ASP.NET applications, the default credentials are the user credentials of the logged-in user, or the user being impersonated.

Note - The ICredentials instance returned by DefaultCredentials cannot be used to view the user name, password, or domain of the current security context.

Conclusion

This is my first article and a very simple one. Any questions or suggestions are welcome ! Bye !

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Bruno Capuano


Member
Now I'm Spain. 100 % Vs.Net development working today, ! .. and trying to reload !!
Occupation: Web Developer
Location: United States United States

Other popular Web Services articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 43 (Total in Forum: 43) (Refresh)FirstPrevNext
GeneralDowload file from internet through proxy in vb.net Pinmembervu van phuong22:22 1 Jan '09  
QuestionAdding proxyserver to authenticate Pinmemberv-11dals19:10 26 Nov '08  
GeneralError consuming WS. PinmemberVladValle6:22 25 Jun '08  
GeneralCreate proxy server using c# PinmemberArron Xiao22:58 13 Aug '07  
QuestionCCproxy Problem Pinmemberbkashok1:03 28 Feb '07  
GeneralQuestion about proxy in webrequest (!!Help!!) Pinmemberstancrm3:19 3 May '06  
QuestionProxy with authentication retire something. Pinmembericerein23:52 4 Dec '05  
GeneralTrying to create a app through proxies PinsussAnonymous19:06 28 May '05  
GeneralRe: Trying to create a app through proxies PinmemberBruno Capuano21:20 29 May '05  
Generalcomunicación con formularios PinsussCarlos Cruz Espino15:17 24 Jan '05  
GeneralRe: comunicación con formularios PinmemberBruno Capuano3:09 25 Jan '05  
GeneralThe request failed with HTTP status 417: Expectation Failed. Pinmemberdbrizuela9:17 23 Nov '04  
GeneralRe: The request failed with HTTP status 417: Expectation Failed. PinmemberBruno Capuano3:15 25 Jan '05  
GeneralRe: The request failed with HTTP status 417: Expectation Failed. Pinmemberdbrizuela3:55 25 Jan '05  
GeneralRe: The request failed with HTTP status 417: Expectation Failed. PinmemberBruno Capuano5:54 25 Jan '05  
GeneralProxy with authentication (SQUID) PinsussAlberto Gastaldo2:34 25 Aug '04  
GeneralRe: Proxy with authentication (SQUID) PinmemberBruno Capuano11:33 13 Sep '04  
GeneralRe: Proxy with authentication (SQUID) PinmemberMimmoEv6:30 30 Nov '05  
GeneralRe: Proxy with authentication (SQUID) [modified] PinmemberMichael Freidgeim21:29 6 Sep '06  
GeneralProxy with authentication (SQIOD) PinsussAlberto Gastaldo2:33 25 Aug '04  
GeneralGetDefaultProxy? PinmemberTom Gaskins15:57 5 Jun '04  
GeneralRe: GetDefaultProxy? PinmemberBruno Capuano6:18 7 Jun '04  
Generalkerberos Pinmemberreso88@hotmail.com22:24 22 Sep '03  
GeneralThe request failed with HTTP status 407: Proxy Access Denied? PinmemberNguyen MInh Tuan18:09 21 Jul '03  
GeneralRe: The request failed with HTTP status 407: Proxy Access Denied? PinmemberBruno Capuano12:43 25 Jul '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 29 Jun 2003
Editor: Nishant Sivakumar
Copyright 2003 by Bruno Capuano
Everything else Copyright © CodeProject, 1999-2009
Web19 | Advertise on the Code Project