|
Connecting to Web Services through Firewalls and Network Security (VB.Net) |
|
|
Written by: Evan Cummings
Connecting to Web Services through Firewalls and Network SecurityWorking between a variety of servers hosting specific resources is common hurdle we may come upon as application developers. As the need continues to grow for more and more mobile and distributed computing power, the more we will need to work between specific resources to accomplish our tasks. In order to maintain the integrity of all of these servers, layers of security help to keep the right people in, and the wrong people out. This poses an interesting challenge to developers, however. I need resource X which is located on server Y, but firewall Z is standing in the way -- what do I do?
The .NET Framework has a rich set of classes for working with and negoiating with that firewall in the middle that is preventing us from getting us to our data or web service. By using these tools, we can assert that we have the right priveledges to access that resource so that we can continue on to our goal.
System.Net
The simplest method I have come across to acheive this is to make good use of the System.Net namespace. This library has numerous classes available to us to navigate our networks.
To implement this, we need to first get ahold of the network proxy in between:
Dim svc As New Webservice 'Generic Webservice we want to access Dim proxy As System.Net.WebProxy = System.Net.WebProxy.GetDefaultProxy() 'Returns an object representing the proxy we are working with
Now that we have an instance of the proxy we are working with, we need to present our credentials to it, in a format it understands. This is acheived by using the NetworkCredential class:
Dim credentials As New System.Net.NetworkCredential credentials.Domain = "myDomain" 'The domain you are working within credentials.Username = "myUserName" 'Username of an entity with sufficient permissions to access the resource credentials.Password = "myPassword" 'Password for this account
To continue, we need to add this new credential information to a CredentialCache that is designed to represent all of the essential details we need to communicate with the proxy. This includes passing it the proxy's address, the authorization type, and our credentials object we just created:
Dim credentialsCache As New System.Net.CredentialCache credentialsCache.Add(proxy.Address, "NTLM", credentials)
The authType parameter supports four different values - NTLM (NT LAN Manager), Digest, Kerberos, and Negotiate. These types represent various network authentication schemes that you may need to specificy based on the network structure and security requirements.
Next, we simply provide our proxy object with this credential cache, and finish the circle by providing our proxy to the web service object:
myProxy.Credentials = myCredentialCache svc.Proxy = proxy
At this point, assuming we have adequate credentials, we should now be able to make a call to our web service with successfully negotiating our way through any firewalls or ISA type servers that may stand in the way.
Content: Web Service, VB.NET, Security, System.Net
|
|
|
|
|
|