SOAP HEADER

Discussion in 'ASP .Net Web Services' started by Ravi, May 5, 2006.

  1. Ravi

    Ravi Guest

    Hi

    I consume a webservice in C# and want to send the user name and password in
    the SOAP header. I will really appreciate some help or an example
    --
    Thanks
    Ravi
     
    Ravi, May 5, 2006
    #1
    1. Advertising

  2. public class UserCredentialsSoapHeader : SoapHeader
    {
    public string UserName;
    public string Password;
    }


    [SopHeader("UserCredentials")]
    public MyWebService : WebService
    {
    //1) Must be public
    //2) Name must be the same as the name given in the above attribute
    public UserCredentialsSoapHeader UserCredentials;

    [WebMethod]
    public string HelloWorld()
    {
    if (UserCredentials == null)
    throw new ........("UserCredentials required");

    return "Hello " + UserCredentials.UserName;
    }
    }


    I have just changed my webservices from using this approach to a ticket
    approach instead. I return a Guid from a LogIn(username, password) method.
    The Guid is a key to the username/password in the Cache object. It is must
    clearer in my opinion as to which methods require a login now, because they
    all start with "Guid SessionID"



    Pete
     
    Peter Morris [Droopy eyes software], May 5, 2006
    #2
    1. Advertising

  3. Ravi

    Ravi Guest

    hi Peter

    Sorry If I didn't explained my self properly the first Time. Your
    explainationed assumed that my web servrice is the host unfortunately it's
    otherwise.

    I am using C# but consumed a webservice which is the host and written in
    PHP. The host webservice used WSsecurity. I have to pass a user name and
    password in the soapheader everytime I make a call to the host webservice. I
    have do clue how to do this. Pleae help. Again I am the client of the
    webserive.
    --
    Thanks
    Ravi


    "Peter Morris [Droopy eyes software]" wrote:

    > public class UserCredentialsSoapHeader : SoapHeader
    > {
    > public string UserName;
    > public string Password;
    > }
    >
    >
    > [SopHeader("UserCredentials")]
    > public MyWebService : WebService
    > {
    > //1) Must be public
    > //2) Name must be the same as the name given in the above attribute
    > public UserCredentialsSoapHeader UserCredentials;
    >
    > [WebMethod]
    > public string HelloWorld()
    > {
    > if (UserCredentials == null)
    > throw new ........("UserCredentials required");
    >
    > return "Hello " + UserCredentials.UserName;
    > }
    > }
    >
    >
    > I have just changed my webservices from using this approach to a ticket
    > approach instead. I return a Guid from a LogIn(username, password) method.
    > The Guid is a key to the username/password in the Cache object. It is must
    > clearer in my opinion as to which methods require a login now, because they
    > all start with "Guid SessionID"
    >
    >
    >
    > Pete
    >
    >
    >
     
    Ravi, May 6, 2006
    #3
  4. The web reference will be aware of the header + its structure. So in my
    example the code would be


    UserCredentials credentials = new UserCredentials;
    credentials.UserName = "Peter";
    credentials.Password = "Morris";

    SomeWebService service = new SomeWebService();
    service.UserCredentialsValue = credentials;
    string result = service.HelloWorld();


    I haven't used WSSecurity etc, but that is how it works with my example.
     
    Peter Morris [Droopy eyes software], May 6, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sham Ramakrishnan
    Replies:
    2
    Views:
    8,471
    Sham Ramakrishnan
    Jul 1, 2003
  2. mooseshoes

    To SOAP or Not To SOAP?

    mooseshoes, Sep 4, 2003, in forum: XML
    Replies:
    3
    Views:
    425
    Heinz Häberle
    Sep 21, 2003
  3. Nagesh
    Replies:
    2
    Views:
    9,508
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Aug 12, 2006
  4. mlt
    Replies:
    2
    Views:
    907
    Jean-Marc Bourguet
    Jan 31, 2009
  5. Peter van der veen

    How to add SOAP header to a SOAP message?

    Peter van der veen, Nov 8, 2006, in forum: ASP .Net Web Services
    Replies:
    6
    Views:
    641
    J. Dudgeon
    Nov 14, 2006
Loading...

Share This Page