2010-05-31 46 views
4

我已经将一个基于wsdl的轴作为服务引用导入到VS 2008项目中。在WCF代理中实现Ws安全性

我需要能够传递安全细节,例如用户名/密码和nonce值来调用基于轴的服务。

我特地到这样做是为了WSE,这是我了解世界恨(有没有问题)

我有WCF的经验非常少,但工作如何物理现在所说的终点,由于SO ,但不知道如何成立的SOAPHeaders如下所示的模式:

<S:Envelope 
    xmlns:S="http://www.w3.org/2001/12/soap-envelope" 
    xmlns:ws="http://schemas.xmlsoap.org/ws/2002/04/secext"> 
    <S:Header> 
     <ws:Security> 
      <ws:UsernameToken> 
       <ws:Username>aarons</ws:Username> 
       <ws:Password>snoraa</ws:Password> 
      </ws:UsernameToken> 
     </wsse:Security> 
     ••• 
    </S:Header> 
    ••• 
</S:Envelope> 

任何帮助非常赞赏

谢谢,马克

回答

4

为了调用这些服务,通常使用basicHttpBinding(即没有WS- *实现的SOAP 1.1)或wsHttpBinding(SOAP 1.2,带有WS- *实现)。

主要问题将获得所有的安全参数。我有一个类似的网络服务(基于Java的),我需要调用 - 这里是我的设置和代码:

app./web.config

<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="SoapWithAuth" useDefaultWebProxy="false"> 
      <security mode="TransportCredentialOnly"> 
       <transport clientCredentialType="Basic" proxyCredentialType="None" realm="" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
    <endpoint name="SoapWithAuth" 
        address="http://yourserver:port/YourService" 
        binding="basicHttpBinding" 
        bindingConfiguration="SoapWithAuth" 
        contract="IYourService" /> 
    </client> 
</system.serviceModel> 

,然后在客户端的代码中调用时该服务,你需要这段代码:

IYourServiceClient client = new IYourServiceClient(); 

client.ClientCredentials.UserName.UserName = "username"; 
client.ClientCredentials.UserName.Password = "top-secret"; 

这有帮助吗?

+1

当然可以,你知道如何为我们的安全设置一个随机数值吗? – harrisonmeister 2010-05-31 18:59:56

0

WCF客户端代理不支持密码摘要选项。唯一的方法是自己构建UsernameToken,然后在发送消息之前将其注入到SOAP头中。

我有一个类似的问题,描述为here,这应该足以帮助您解决同样的问题。

我最终为UsernameToken使用了旧的WSE3.0库,而不是自己编码哈希算法,然后使用自定义行为来改变SOAP头。