Geeks With Blogs

News Internet - .Net user group technical events, emerging .Net technologies;
General - Eco-travel, health and fitness, current events;
Community - Active volunteer with Hands On Miami, Non-Profit Ways;
.Net Framework - Detected 3.5 SP1 .NET Framework. No update needed ;
creative zen converter
Geekette Mai Blog

From what I understand that .NET is rich with classesa andd Web Service Suppor, and SOAP headers arewith the authentication theme...

The first thing to do this is create a class that will represent the header:

Public class AuthToken: SoapHeader

{

      protected string m_strAuthToken;

      public  AuthoToken ( )

       {

            m_strAuthToken = " " ;

        }

        public String Token

        {

           Get   {  return  m_strAuthToken;  }

           Set   {  m_strAuthToken = Value; }

          }

}

As it happens,  SOAP Headers within .Net Framework are actually implemented as attributes of the Web  Method.   Therfore, within your Web Service class you will create an instance of the header class that may be referenced by each interested Web method:

 

public class Service1: System.Web.Services.WebService

     {

           public AuthoToken  m_authotoken;

           ...

          [webmethod]

[soapHeader  ( "m_authToken "' Direction = SoapHeaderDirection.In)]

public string  MyBillablewebmethod ( )

       {

         return   " " ;

       }

//continue processing...

...

      }

}

We need to inform .Net that we infact understand the SOAP Header or .Net will throw the require SOAP fault.   Soap 's must understand constraint wasn't met and we will have to provide an implementation for Authenticate( ) to actual validate the authentication token.

 

The key for web Service proxy you must use wsdl.exe or via VS .Netadd a reference at the menu option Or if you download a WSDL file for Web Service that require a SOAP header than you must do this

public class service1:

                      system.web.services.protocals.soaphttpclientprotocol

 

{

public  AuthToken  AuthTokenValue;

                    ...

                    [system.xml.serialization.xmlrootattribute(Naspace= " http:// tempuri.org / " , isNullable=false)]

public  class AuthToken:  SoapHeader  

               {

public string Token ;

               }

}

When you create an instance proxy in your main application file, you will create an instance of AutToken class and assign  the string:

Service1  objSvc  =  New Service  ( ) ;

//Create the header itself.   Thios header will go to

//web service processing

objSvc.AuthTokenValue =  new AuthToken ( ) ;

ObjSvc.AuthTokenValue.Token = < actual token value > ;

// Call  the Web Service

string  strResult  = objSvc.MybillableWebMethod ( ) ;

.Net will make sure the SOAP header is created and filled with the authentication token's value

 

 

Posted on Friday, February 12, 2010 12:56 PM | Back to top


Comments on this post: SOAP Header required information from Web Service

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Mai Nguyen | Powered by: GeeksWithBlogs.net