gpt4 book ai didi

c# - WCF 消息凭证实现细节

转载 作者:行者123 更新时间:2023-11-30 16:35:39 27 4
gpt4 key购买 nike

我正在寻找一些技术细节,了解在使用 WCF 绑定(bind)进行消息交换期间实际用户名 + 密码(凭据)的存储位置,如下所示。

<bindings>
<wsHttpBinding>
<binding name="wsHttp">
<security mode="TransportWithMessageCredential">
<transport/>
<message clientCredentialType="UserName"
negotiateServiceCredential="false"
establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>

然后在客户端应用程序中,我调用此服务来传递一组有效的凭据,如下所示

using (SupplierServiceClient client = new SupplierServiceClient()) {
client.ClientCredentials.UserName.UserName = "admin";
client.ClientCredentials.UserName.Password = "password";

SupplierList = client.GetSupplierCollection();
}

起初我假设 WCF 正在获取这些数据并将其放入 SOAP header 中,但它在 WSDL 中似乎不是这样……有什么帮助吗?

编辑:

下面是客户端在生产环境中的安全配置

<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" establishSecurityContext="false" />
</security>

最佳答案

通过设置 UserNameCredentials,您实际上是在利用用户名 token 配置文件。这会导致将 token 作为 SOAP header 添加到消息中。 SOAP header 看起来像这样:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<env:Header>
<wsse:UsernameToken>
<wsse:Username>jdoe</wsse:Username>
<wsse:Password>passw0rd</wsse:Password>
<wsse:Nonce><!-- optional nonce here --></wsse:Nonce>
</wsse:UsernameToken>
</env:Header>
<env:Body>
<!-- body here -->
</env:Body>
</env:Envelope>

现在,我不太确定您为什么要提到 WSDL。 token 不会出现在 WSDL 中,尽管 WSDL 应该包含有关操作的正确 WS-Policy 注释。这将使 WSDL 的使用者发现他们实际上需要将 UsernamePasswordToken 发送到请求中。

最后,有人提出了 RequestSecurityToken (RST),但如果您只是使用简单的 UsernameToken 身份验证,则不应(不需要)涉及 RST。唯一需要涉及 RST 的情况是您使用 WS-Trust 与安全 token 服务器 (STS) 进行 token 交换。

关于c# - WCF 消息凭证实现细节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1637281/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com