回答
我不完全确定这是你在找什么,但在这里你去。
MyClient client = new MyClient();
client.ClientCredentials.UserName.UserName = "u";
client.ClientCredentials.UserName.Password = "p";
不确定这是否是您要查找的内容,但下面是使用客户端凭据进行身份验证的有效代码示例。
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()
我通过将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组。
这对我有效。
- 1. WCF无法生成客户端代理
- 2. Silverlight + WCF +客户端凭据
- 3. 如何将代理凭证设置为特定的wcf客户端?
- 4. 设置客户端凭证
- 5. 如何在代码中使用wsDualHttpBinding设置WCF客户端?
- 6. 如何为特定位置的WCF服务生成客户端代理?
- 7. 向生成的WCF客户端代理代码添加方法
- 8. 用客户端行为生成WCF代理
- 9. WCF wrap代理客户端
- 10. WCF通过客户端的Windows凭据
- 11. 如何在WCF客户端服务代理上设置HTTP代理(WebProxy)?
- 12. 如何在WCF上使用HttpTransportBindingElement设置代理凭证?
- 13. 任何用于渠道管理的WCF客户端代理生成器?
- 14. WCF客户端代理生成新的方法除了没有
- 15. 为Java中的WCF Web服务生成代理客户端
- 16. 数据成员订单从wcf客户端代理生成的类中丢失
- 17. 如何配置cURL以使用客户端代理?
- 18. WCF验证服务 - 如何使用Apache Axis生成客户端?
- 19. 禁用WCF客户端的Web代理?
- 20. 用于ASP .NET客户端的WCF客户端代理
- 21. 如何设置Unirest代理的凭据?
- 22. 如何使用svcutil.exe创建客户端代理ib WCF?
- 23. 使用WSDL不匹配的的ServiceContract生成WCF代理客户端,XmlSerializerFormat属性
- 24. 生成的WCF数据服务客户端的System.ServiceModel配置节
- 25. 如何生成无客户端后缀wcf服务的代理类?
- 26. 为HTTP客户端设置代理
- 27. 的Apache CXF客户端代理设置
- 28. 泽西客户端+设置代理
- 29. 我在哪里可以在我的WCF客户端中指定代理凭证?
- 30. 如何使用的RESTEasy客户端生成器设置用户名和密码?
它似乎不适用于NTLM代理。我需要填写`client.ClientCredentials.Windows`才能使它工作。 – 2010-04-02 10:25:33