Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Username and Password in the service side of a WCF call?

When I supply credentials at client with following code:

myChannelFactory.Credentials.UserName.UserName = "username";
myChannelFactory.Credentials.UserName.Password = "password";

Then on server side I see that these credentials are available in

operationContext.IncomingMessageHeaders[1]

However is there any more convenenient method to get the UserName and password? All I see in OperationContext is chaos of properties and untyped lists and I cant find anything that indicates where I can get this.

like image 885
Filip Nguyen Avatar asked Mar 02 '11 16:03

Filip Nguyen


People also ask

How do I bypass WCF username and password?

To configure a service to authenticate its clients using Windows Domain username and passwords use the WSHttpBinding and set its Security. Mode property to Message . In addition you must specify an X509 certificate that will be used to encrypt the username and password as they are sent from the client to the service.

How do I validate my username and password in C#?

Text + "' and Password= '" + TextBoxSignPass. Text + "'"; SqlCommand cmd = new SqlCommand(checkUser, con); cmd. ExecuteNonQuery(); con. Close();

How do I send credentials in SOAP header?

At the client. Add the web service reference as usual. Instantiate a new object of the type MyWebService. In addition instantiate a new object of the type Authentication and assign the username and password properties. Next, assign this to the Service credentials property of the MyWebService instance.


1 Answers

You can use the static Current property on the ServiceSecurityContext class to get the current ServiceSecurityContext for the operation that is being called.

You can then use the PrimaryIdentity property in order to get the identity of the user with the credentials passed in.

However, it will not (nor should it), expose the password. If you truly need the password, then you will have to drop down to the message level and inspect the headers, as you've seen.

like image 130
casperOne Avatar answered Oct 18 '22 19:10

casperOne