消费通过互联网代理服务器,使用C#WCF客户端的Web服务;提供代理服务器认证 [英] Consuming a web service through an internet proxy server, using a WCF client in C#; providing proxy server authentication
问题描述
我有一个消费Web服务的客户端程序。它工作的很好的一些设施。现在我有一种情况,一个新的客户通过代理服务器连接到互联网,我的程序试图访问Web服务得到HTTP状态407:要求代理身份验证。误差
I have a client program that consumes a web service. It works quite well in a number of installations. Now I have a situation where a new customer connects to the internet via a proxy server, and my program's attempt to access the web service gets the "HTTP status 407: Proxy authentication required" error.
我想,互联网接入,包括代理服务器地址的所有配置,端口号和验证将在控制面板Internet选项做的,我不会担心,在code,甚至在app.config,Web服务客户端。
I thought that all the configuring of internet access, including proxy server address, port number and authentication would be done in the Control Panel Internet Options, and that I wouldn't have to worry about that in the code, or even in the app.config, of the Web Service client.
有我全搞错了?
我已经在平均时间做的是给用户配置代理服务器的用户名和密码的机会,然后在我的code我做到以下几点:
What I have done in the mean time is give the user the chance to configure the proxy user name and password, and then in my code I do the following:
webServiceClient.ClientCredentials.UserName.UserName = configuredUsername;
webServiceClient.ClientCredentials.UserName.Password = configuredPassword;
但我不知道这是正确的事情。因为在我看来,上述ClientCredentials将引用Web服务绑定/安全性,而不是网络代理服务器。
But I don't know that this is the right thing. Because it seems to me that the above ClientCredentials would refer to the web service binding/security, not to the internet proxy server.
我想我可以在用户尝试,但我宁愿肯定我在做什么第一。
I suppose I can try it at the customer, but I'd rather be sure of what I'm doing first.
推荐答案
我发现了如何做这件事情,有贡献者的帮助下,这在尝试各种各样的事情乱舞我忘了另一个论坛。所以,谢谢你,现在被遗忘的人。
I found out how to do this thing, with the help of a contributor to another forum which in the flurry of trying all sorts of things I've forgotten. So thank you to that now forgotten person.
这里的code,在年底工作(适当伪装,但给出正确的想法):
Here's the code that worked in the end (suitably disguised, but gives the right idea):
BasicHttpBinding binding = new BasicHttpBinding("APISoap"); /* APISoap is the name of the binding element in the app.config */
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;
binding.UseDefaultWebProxy = false;
binding.ProxyAddress = new Uri(string.Format("http://{0}:{1}", proxyIpAddress, proxyPort));
EndpointAddress endpoint = new EndpointAddress("http://www.examplewebservice/api.asmx");
WebServiceClient client = new WebServiceClient(binding, endpoint);
client.ClientCredentials.UserName.UserName = proxyUserName;
client.ClientCredentials.UserName.Password = proxyPassword;
这篇关于消费通过互联网代理服务器,使用C#WCF客户端的Web服务;提供代理服务器认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!