简体   繁体   English

如何使用WCF在WSSE安全标头中设置密码类型“PasswordText”

[英]How to set password type “PasswordText” in the WSSE Security Header with WCF

I want to have an wsse security header in wich the Password Type is set to "PasswordText" like in the following SOAP snipet: 我希望有一个wsse安全标头,密码类型设置为“PasswordText”,如下面的SOAP snipet:

<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. 但我得到的只是一个没有Type属性的简单密码标签。

<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? 在代码或app.cfg中指定它的正确方法是什么? Hier is my code so far: 到目前为止,Hier是我的代码:

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;

Maybe this will help someone else who finds this in a search like I did. 也许这会帮助那些像我一样在搜索中发现这一点的人。 I solved it by changing the MessageSecurityVersion. 我通过更改MessageSecurityVersion解决了这个问题。

In app.config custom binding: 在app.config自定义绑定中:

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

In C#: 在C#中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM