How to set security token in WCF?

I am updating the application from .net 1.1 to 3.5. This application connects to the WCF service. Previously, the web service client was configured to use a security token, for example:

RegistrationWSWse registrationService = new RegistrationWSWse(); Microsoft.Web.Services2.Security.Tokens.UsernameToken token = new Microsoft.Web.Services2.Security.Tokens.UsernameToken("some username", "some password", Microsoft.Web.Services2.Security.Tokens.PasswordOption.SendPlainText ); registrationService.RequestSoapContext.Security.MustUnderstand=false; registrationService.RequestSoapContext.Security.Tokens.Add(token); 

Now I have added a new service in Visual Studio to the web service, but the automatically generated code does not provide any way to set the security header, for example, above.

Is this something you need to configure in the configuration file, system.serviceModel ?


Update

The reason I did not see the username and password properties was because I was working with the service interface, and not with the actual implementation class.

I managed to install these things by hovering an instance of the type, for example:

 ((RegistrationWSClient)registrationWs).ChannelFactory.Credentials.UserName.UserName = userName; ((RegistrationWSClient)registrationWs).ChannelFactory.Credentials.UserName.Password = password; 

Another important thing you need to do is update the app.config client file. If you do not, the username / password will not be set to its SOAP header. Example:

 <security mode="TransportWithMessageCredential" /> 
+7
security wcf webservice-client
source share
1 answer

Check this article on MSDN . This post also contains some good information about your question.

+1
source share

All Articles