2008-09-19 54 views

回答

3

我不完全确定这是你在找什么,但在这里你去。

MyClient client = new MyClient(); 
    client.ClientCredentials.UserName.UserName = "u"; 
    client.ClientCredentials.UserName.Password = "p"; 
+2

它似乎不适用于NTLM代理。我需要填写`client.ClientCredentials.Windows`才能使它工作。 – 2010-04-02 10:25:33

1

不确定这是否是您要查找的内容,但下面是使用客户端凭据进行身份验证的有效代码示例。

Dim client As ProductServiceClient = New ProductServiceClient("wsHttpProductService") 
    client.ClientCredentials.UserName.UserName = "username" 
    client.ClientCredentials.UserName.Password = "password" 
    Dim ProductList As List(Of Product) = client.GetProducts() 
    mView.Products = ProductList 
    client.Close() 
2

我通过将Active Directory用户添加到应用程序池>身份而不是网络服务来解决此问题。此用户也位于有权通过代理服务器浏览Internet的组中。还要将此用户添加到客户端主机服务器上的IIS_WPG组。

在下面的代码中,第一位用WCF服务验证客户端。第二位假设将crendentials传递给内部代理服务器,以便客户端在DMZ服务器上调用WCF服务。但我不认为代理部分是有效的。无论如何,我将离开代码。

 // username token credentials 
     var clientCredentials = new ClientCredentials(); 
     clientCredentials.UserName.UserName = ConfigurationManager.AppSettings["Client.Mpgs.Username"]; 
     clientCredentials.UserName.Password = ConfigurationManager.AppSettings["Client.Mpgs.Password"]; 
     proxy.ChannelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials)); 
     proxy.ChannelFactory.Endpoint.Behaviors.Add(clientCredentials); 

     // proxy credentials 
     //http://kennyw.com/indigo/143 
     //http://blogs.msdn.com/b/stcheng/archive/2008/12/03/wcf-how-to-supply-dedicated-credentials-for-webproxy-authentication.aspx 
     proxy.ChannelFactory.Credentials.Windows.ClientCredential = new System.Net.NetworkCredential 
                    (
                     ConfigurationManager.AppSettings["Client.ProxyServer.Username"] 
                     , ConfigurationManager.AppSettings["Client.ProxyServer.Password"] 
                     , ConfigurationManager.AppSettings["Client.ProxyServer.DomainName"] 
                    ); 

在我的web.config我已经使用了以下

<system.net> 
    <defaultProxy useDefaultCredentials="true"> 
     <proxy usesystemdefault="True" proxyaddress="http://proxyServer:8080/" bypassonlocal="False" autoDetect="False" />  </defaultProxy> 
</system.net> 
<system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
      <binding name="WSHttpBinding_ITest" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/> 
       <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/> 
       <security mode="TransportWithMessageCredential"> 
        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/> 
        <message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default"/> 
       </security> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="https://wcfservice.organisation.com/test/test.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ITest" contract="Test.Test" name="WSHttpBinding_ITest"/> 
    </client> 
</system.serviceModel> 

上面的代码从我的本地机器的工作原理。当我将代码上传到开发服务器时,它不起作用。我查看了代理服务器日志,并在下面显示,

2011-06-14 05:21:10 2 11.11.11.11 - - authentication_failed DENIED“Organization/Finance” - 407 TCP_DENIED CONNECT - tcp wcfservice.organisation.com 443/- - - 11.11.11.11 612 161 -

2011-06-14五时21分10秒6 11.11.11.152服务器名称$ - policy_denied被拒绝 “组织/财经” - 403 TCP_DENIED CONNECT - TCP wcfservice.organisation.com 443/- - - 11.11.11.205 185 361 -

我们的智能系统管理员DF添加了Active Directory用户到应用程序池>身份而不是网络服务。此用户也位于有权通过代理服务器浏览Internet的组中。还要将此用户添加到客户端主机服务器上的IIS_WPG组。

这对我有效。

相关问题