【问题标题】:.NET WCF calling .asmx with WS-Security.NET WCF 使用 WS-Security 调用 .asmx
【发布时间】:2009-10-27 15:42:57
【问题描述】:

.NET WCF 客户端程序能否调用使用 WS-Security 进行登录的现有(供应商提供的).asmx Web 服务?

在我们的例子中,供应商提供了一个带有 WS-Security 的 .asmx Web 服务。我们将首先尝试使用 SOAPUI 和 WCFTestHarness 或 WCFTestClient 来访问它。如果可能,宁愿使用 WCF。

谢谢,

尼尔·沃尔特斯

【问题讨论】:

    标签: .net wcf web-services


    【解决方案1】:

    是的,当然。 WCF 对 WS-Security 有很好的支持。服务需要什么样的令牌进行身份验证?

    假设它只是用户名/密码,您只需将绑定配置为使用 TransportWithMessageCredential 安全性,其中客户端凭据类型为 UserName(注意:您必须使用 HTTPS 来执行此操作)。首先,像这样定义一个绑定:

    <basicHttpBinding>
        <binding name=“MyBinding”>
            <security mode=“TransportWithMessageCredential”>
                <transport clientCredentialType=“None” />
                <message clientCredentialType=“UserName” />
            </security>
        </binding>
    </basicHttpBinding>
    

    然后配置您的端点以使用此绑定:

    <endpoint address="https://somewhere.com/TargetService.asmx" binding="basicHttpBinding" bindingConfiguration="MyBinding" />
    

    然后在运行时,假设您使用的是生成的代理(即 ClientBase),您只需像这样设置客户端凭据:

    TargetServiceClient client = new TargetServiceClient();
    client.Credentials.UserName.UserName = "myusername";
    client.Credentials.UserName.Password = "mypassword";
    

    【讨论】:

    • WCF 支持几乎所有可以想象的 WS-* 标准 :-)
    • @marc_s 如果没有,您可以自己添加。我喜欢我一些 WCF。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-29
    • 1970-01-01
    • 2012-05-28
    相关资源
    最近更新 更多