SOAP HEADER

R

Ravi

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
 
P

Peter Morris [Droopy eyes software]

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
 
R

Ravi

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.
 
P

Peter Morris [Droopy eyes software]

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top