Home   |   QuickStart Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   
  |   I want my samples in...      

ASP.NET 2.0 Web Services QuickStart Tutorial

SOAP Headers

This sample demonstrates the use of ASP.NET Web Services's support for SOAP headers. The sample employs an authorization header sent with the request that has username/password information. The first call to the WebMethod does not include the SOAP header and thus fails. The second call to the WebMethod includes the SOAP header and thus returns successfully.

WARNING: This sample is for demonstration purposes only. Username/password information is sent in plain text, which should never be done in a real application. It is not secure without modification.

		
// On the server, create the AuthHeader class which extends from SoapHeader
public class AuthHeader : SoapHeader {
    public string Username;
    public string Password;
}
   
// On the client, create a new instance of the AuthHeader class
AuthHeader myHeader = new AuthHeader();

//WARNING: This sample is for demonstration purposes only.  Username/password information is sent in plain text,
//which should never be done in a real application. It is not secure without modification.  
myHeader.Username = "JaneDoe";
myHeader.Password = "password";

// Set the AuthHeader public member of the Web service instance to myHeader
service.AuthHeaderValue = myHeader;
    
// Call the Web service, which automatically sends the header with the request
string answer = service.HelloWorld();
C#

Run VB Sample
Run Sample View Source



Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2004 Microsoft Corporation. All rights reserved.