我想要一个wsse安全标头,其中Password Type设置为"密码文本"类似于以下SOAP片段:
<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>
但我得到的只是一个没有Type属性的简单密码标记。
<wsse:UsernameToken u:Id="UsernameToken-2">
<wsse:Username>usrnm</wsse:Username>
<wsse:Password>pwd</wsse:Password>
</wsse:UsernameToken>
在代码或app.cfg中指定它的正确方式是什么?这是我到目前为止的代码:
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;
也许这会帮助其他像我一样在搜索中找到它的人。我通过更改MessageSecurityVersion解决了这个问题。
在app.config中自定义绑定:
<security authenticationMode="UserNameOverTransport"
messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" />
在C#中:
var securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
securityElement.MessageSecurityVersion = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;