Reputation: 25537
I am working on a soap webservice in c#. It look like this:
public class MyService : System.Web.Services.WebService
{
public MyService()
{
}
[WebMethod]
public string Hello()
{
return "hello";
}
}
and I added a service reference to this web service from another website, so I can access the Hello()
method from there using the code:
MyServiceSoapClient client = new MyServiceSoapClient();
client.Hello();
Now I need to pass the credentials to that web service. I have tried:
MyServiceSoapClient client = new MyServiceSoapClient();
client.ClientCredentials.UserName.UserName = "test";
client.ClientCredentials.UserName.Password = "pwd";
client.Hello();
But I could not manage to get these credentials in the webservice ( in the Hello()
method).
How can I get these values in the webservice?
Upvotes: 0
Views: 2745
Reputation: 127603
You get the user via the WebService.User property. This will give you the username but there is no way to retrieve the passed password, this is by design as the authentication happens at the IIS level before your WebService is run.
public class MyService : System.Web.Services.WebService
{
public MyService()
{
}
[WebMethod]
public string Hello()
{
return "hello, my name is " + User.Identity.Name;
}
}
Upvotes: 1