strangeoptics
strangeoptics

Reputation: 753

How to set password type "PasswordText" in the WSSE Security Header with WCF

I want to have an wsse security header in which the Password Type is set to "PasswordText" like in the following SOAP snippet:

<wsse:UsernameToken wsu:Id="UsernameToken-2">
   <wsse:UsernaWme>usrnm</wsse:Username>
   <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pwd</wsse:Password>
</wsse:UsernameToken>

But all I get is a simple password tag without the Type attribute.

<wsse:UsernameToken u:Id="UsernameToken-2">
  <wsse:Username>usrnm</wsse:Username>
  <wsse:Password>pwd</wsse:Password>
</wsse:UsernameToken>

What is the proper way to specify it in the code or in the app.cfg? Here is my code so far:

service.ClientCredentials.UserName.UserName = "usrnm";
service.ClientCredentials.UserName.Password = "pwd";

var securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
securityElement.AllowInsecureTransport = true;

var encodingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
var transportElement = new HttpTransportBindingElement();

var binding = new CustomBinding(securityElement, encodingElement, transportElement);
service.Endpoint.Binding = binding;

Upvotes: 4

Views: 8838

Answers (1)

dlumpp
dlumpp

Reputation: 1198

Maybe this will help someone else who finds this in a search like I did. I solved it by changing the MessageSecurityVersion.

In app.config custom binding:

<security authenticationMode="UserNameOverTransport" 
   messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" />

In C#:

var securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
securityElement.MessageSecurityVersion = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;

Upvotes: 2

Related Questions