-->

对于第三方SOAP 1.1纯文本的用户名凭据通过SSL WCF服务客户端配置(WCF client

2019-09-21 09:10发布

我试图连接到第三方SOAP 1.1服务要求SSL安全和用户名/密码凭据。 什么是预期的一个例子是:

<soapenv:Header>
    <wsse:Security>
        <wsse:UsernameToken>
            <wsse:Username>username</wsse:Username>
            <wsse:Password>password</wsse:Password>
        </wsse:UsernameToken>
    </wsse:Security>
</soapenv:Header>

我的客户端配置如下:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="thirdpartyservicebindingconfig">
                <security mode="TransportWithMessageCredential">
                    <message clientCredentialType="UserName"
                             algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="https://..." 
                  binding="basicHttpBinding"
                  bindingConfiguration="thirdpartyservicebindingconfig"
                  contract="thirdpartyservicecontract" 
                  name="thirdpartyserviceendpoint" />
    </client>
</system.serviceModel>

服务客户端代码:

var client = new thirdpartyservicecontractclient();

client.ClientCredentials.UserName.UserName = "username";
client.ClientCredentials.UserName.Password = "password";

var result = client.DoSomething();

我收到以下错误异常消息:

安全处理器是无法找到消息中的安全头。 这可能是因为消息是不安全的故障或因为在通信双方之间具有约束力的不匹配。 如果该服务进行了安全配置和客户端没有使用安全措施可能出现这种情况..

编辑:
如果我重新配置的安全模式为“运输”:
<security mode="TransportWithMessageCredential">
我从第三方服务的错误:

com.sun.xml.wss.XWSSecurityException:消息不符合配置的策略[AuthenticationTokenPolicy(S)]:无安全性标头中找到; 嵌套异常是com.sun.xml.wss.XWSSecurityException:com.sun.xml.wss.XWSSecurityException:消息不符合配置的策略[AuthenticationTokenPolicy(S)]:无安全性标头中找到。

我如何配置我的客户端连接到这个服务?

  • WS安全性通过SSL使用明文密码

Answer 1:

它只是恰巧里克施特拉尔有同样的问题。 这里的链接到他的博客描述和解决问题。

问题:

问题是,WCF响应中的时间戳SOAP头。 如果你看一下出站响应和SOAP头,你会看到有一个时间戳那里。 时间戳预计将在返回SOAP响应返回。 请注意,这不是的WS-Security的所以WCF是做一些“特别”在这里,实际上是打破这个服务调用的要求。

解:

BindingElementCollection elements = client.Endpoint.Binding.CreateBindingElements();
elements.Find<SecurityBindingElement>().IncludeTimestamp = false;
client.Endpoint.Binding = new CustomBinding(elements);

上面的代码通过显式地从呼出呼叫其去除的要求为服务器返回它除去时间戳修改绑定配置。 这使得WCF快乐和呼叫经历。



文章来源: WCF client configuration for 3rd party SOAP 1.1 service with plain text username credentials over SSL