Walkthroughs: HTTP Digest on the Client Side
| C#
and VB.NET Code is available when installing the Samples package |
|
| Open this document in seperate window | |
In this walkthhrough, you will:
When using the .NET Framework, implementing HTTP Digest on the client side of your distributed applications could hardly be any easier. This walkthrough will take you through setting up a Web Service reference to a protected Service in Visual Studio .NET and show how few lines of code are necessary to authenticate a client.
RestrictedWs.asmx
We will be referencing and accessing the basic Web Service RestrictedWs.asmx, which we created in the earlier Basic and Advanced walkthrough.



Notice again the Realm IBuySecurely, which was specified in the configuration of the Kabel .NET module for this web application.

In this dialog, you are required to enter the Realm (IBuySecurely) manually. Notice that it is referred to as Domain here.

The 1-Liner
The code needed to call the restricted service is literally only 1 line longer than for a normal service: we merely need add a System.Net.NetworkCredential via the Credential property of the service's proxy class.

401 Exception Handling
Now when calling a secured service, you may want to implement additional exception handling to handle possible HTTP 401. Access Denied responses. This can simply done as follows:
| Exception Handling - C# |
| localhost.RestrictedWs kabelWs = new localhost.RestrictedWs(); kabelWs.Credentials
= new NetworkCredential(username, password); try
}
} |
You make the Call
Below we make two seperate requests:


Feedback
on Help
Copyright © 2002, uthentic.net
All Rights Reserved