With C#, WCF SOAP consumer that uses WSSE plain text authentication?

时光怂恿深爱的人放手 提交于 2019-11-29 00:16:28

That is request for WS-SecureConversation token. It is used by WSHttpSecurity by default unless you change its EstablishSecurityContext property to false. Use this binding instead:

var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);    
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

It will use SOAP 1.1 with UserName token and it will require HTTPS transport.

Edit:

For testing without HTTPS try to use this custom binding:

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);

This looks to me like wsHttpBindings with Transport security using basic username password authentication.

These lines look wrong to me:

binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
binding.Security.Mode = SecurityMode.Message;

Here's how I would expect to see this configured in your app or web.config

<bindings>
  <wsHttpBinding>
    <binding name="ws" >
      <security mode="Transport">
        <transport clientCredentialType="Basic" proxyCredentialType="Basic" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

<client>
  <endpoint address="http://www.bla.com/webservice" binding="basicHttpBinding" contract="bla.IService" name="ws" />
</client>

Then the code would look like this:

var service = new GeneratedProxyClient("basic");
service.ClientCredentials.UserName.UserName = "test";
service.ClientCredentials.UserName.Password = "password";
var input = new InputParameters { Last_Name = "Cambre", First_Name = "Aren" };
var returnData = service.BizarrePeopleSoftNameForMethod(input);

Might be better explained here --> http://msdn.microsoft.com/en-us/library/ms733775.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!