Pet*_*ter 6 authentication proxy web-services internet-connection
我有一个使用Web服务的客户端程序.它在许多安装中都能很好地工作.现在我遇到一个新客户通过代理服务器连接到互联网的情况,我的程序尝试访问Web服务会得到"HTTP状态407:需要代理身份验证"错误.
我认为所有的互联网访问配置,包括代理服务器地址,端口号和身份验证都可以在控制面板的Internet选项中完成,我不必在代码中,甚至在应用程序中担心这一点.配置,Web服务客户端.
我弄错了吗?
我所做的同时是让用户有机会配置代理用户名和密码,然后在我的代码中我执行以下操作:
webServiceClient.ClientCredentials.UserName.UserName = configuredUsername;
webServiceClient.ClientCredentials.UserName.Password = configuredPassword;
Run Code Online (Sandbox Code Playgroud)
但我不知道这是对的.因为在我看来,上面的ClientCredentials将引用Web服务绑定/安全性,而不是Internet代理服务器.
我想我可以在客户处尝试,但我宁愿确定我先做了什么.
我找到了如何做这件事,在另一个论坛的贡献者的帮助下,在一连串尝试各种我忘记的事情.谢谢你那个被遗忘的人.
这是最终有效的代码(适当地伪装,但给出了正确的想法):
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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15596 次 |
| 最近记录: |