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.
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.
Text + "' and Password= '" + TextBoxSignPass. Text + "'"; SqlCommand cmd = new SqlCommand(checkUser, con); cmd. ExecuteNonQuery(); con. Close();
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With