0

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?

1

1 Answer 1

1

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;
    }
}
3
  • Thank you for the answer. while using User.Identity.Name, i am getting the windows username.not the one i had set from the client Commented Jul 30, 2013 at 13:51
  • Read the page on the MSDN for the documentation, you may need to set the authentiaction type up. Commented Jul 30, 2013 at 14:13
  • The other one to check is Context.Session.User.Identity I do not know if that is the same user as User.Identity or not. Commented Jul 30, 2013 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.