【问题标题】:Connecting to a WSE 3.0 Web Service From a WCF Client从 WCF 客户端连接到 WSE 3.0 Web 服务
【发布时间】:2010-11-17 19:35:22
【问题描述】:

我无法从 WCF 客户端连接到第 3 方 WSE 3.0 Web 服务。我已经按照这篇知识库文章中的说明实现了自定义绑定类:

http://msdn.microsoft.com/en-us/library/ms734745.aspx

问题似乎与 Web 服务使用的安全声明有关 - UsernameOverTransport。

当我尝试调用一个方法时,我得到以下异常:

System.InvalidOperationException: 'WseHttpBinding'。'[命名空间]' 绑定为 'MyWebServiceSoap'。'[命名空间]' 合同配置有 需要的认证模式 传输级完整性和 保密。不过交通 不能提供完整性和 保密..

它需要一个用户名、密码和 CN 号码。在供应商提供给我们的示例代码中,这些凭据捆绑在 Microsoft.Web.Services3.Security.Tokens.UsernameToken 中。以下是供应商提供的示例:

MyWebServiceWse proxy = new MyWebServiceWse();

UsernameToken token = new UsernameToken("Username", "password", PasswordOption.SendPlainText);

token.Id = "<supplied CN Number>";

proxy.SetClientCredential(token);

proxy.SetPolicy(new Policy(new UsernameOverTransportAssertion(), new RequireActionHeaderAssertion()));

MyObject mo = proxy.MyMethod();

安装了 WSE 3.0 的 2.0 应用程序可以正常工作。这是来自我的 WCF 客户端的代码的 sn-p:

EndpointAddress address = new EndpointAddress(new Uri("<web service uri here>"));

WseHttpBinding binding = new WseHttpBinding(); // This is the custom binding I created per the MS KB article

binding.SecurityAssertion = WseSecurityAssertion.UsernameOverTransport;
binding.EstablishSecurityContext = false;

// Not sure about the value of either of these next two
binding.RequireDerivedKeys = true;
binding.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;

MembershipServiceSoapClient proxy = new MembershipServiceSoapClient(binding, address);

// This is where I believe the problem lies – I can’t seem to properly setup the security credentials the web service is expecting 

proxy.ClientCredentials.UserName.UserName = "username";
proxy.ClientCredentials.UserName.Password = "pwd";
// How do I supply the CN number?                      

MyObject mo = proxy.MyMethod(); // this throws the exception

我在网上搜索了这个问题的答案。有些资料让我很接近(比如 MS KB 文章),但我似乎无法克服困难。有人可以帮帮我吗?

【问题讨论】:

  • 只是为了确定,您的第三方是否知道 WSE 已过时?
  • 你能解决这个问题吗?有人有想法吗?我目前被困在同一件事上。

标签: wcf web-services wse


【解决方案1】:

我在类似的情况下使用以下绑定配置取得了成功:

<bindings>
   <customBinding>
      <binding name="FNCEWS40MTOMBinding">
         <security enableUnsecuredResponse="true" authenticationMode="UserNameOverTransport"
                   allowInsecureTransport="true" messageProtectionOrder="SignBeforeEncrypt">
            <secureConversationBootstrap />
         </security>
         <mtomMessageEncoding messageVersion="Soap12WSAddressingAugust2004"
                              maxBufferSize="2147483647" />
         <httpTransport maxReceivedMessageSize="2147483647" />
     </binding>
  </customBinding>
</bindings>

希望它也对你有用。

【讨论】:

    【解决方案2】:

    错误消息是指传输级别安全,这通常意味着 https。

    您尚未显示配置文件。但我猜您已将安全性配置为传输(或者作为另一个选择的结果需要它)并使用 http 而不是 https 的地址。

    【讨论】:

    • 您好设拉子,感谢您的回复。我在上面提供的代码中以编程方式将 SecurityAssertion 定义为 UserNameOverTransport。网络服务不使用 https,所以我不认为这是问题所在。
    • 我认为这就是您收到错误的原因。您正在通过传输发送用户名/密码,然后 WCF 会看到密码将通过未加密的线路并拒绝启动服务。
    • 看来这将是 WSE3.0 和 WCF 之间的主要区别,那么。我可以使用没有 SSL 的 WSE 3.0 客户端连接到我的 WSE3 服务,但 WCF 客户端不会连接到 Dave 在他的示例中得到的相同消息。
    猜你喜欢
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    • 2020-07-08
    • 1970-01-01
    • 2013-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多