我创建了使用免费网络服务的简单 WinForms 应用程序 http://www.webservicemart.com/uszip.asmx .但是此应用程序无法使用服务操作并出现错误:
The remote server returned an unexpected response: (407) Proxy Authentication Required (The ISA Server requires authorization to fulfill the request. Access to the Web Proxy service is denied)
创建代理并触发服务操作的代码:
ChannelFactory<ServiceReference1.USZipSoap> proxy = new ChannelFactory<ServiceReference1.USZipSoap>("USZipSoap");
ServiceReference1.USZipSoap client = proxy.CreateChannel();
string str = client.ValidateZip("12345");
MessageBox.Show(str);
这是我公司网络的问题还是webservicemart.com 的代理? ?
我在谷歌上搜索了很多关于更改配置文件、创建自定义绑定(bind)等的信息。但我觉得缺乏更基本的理解......如果这个错误是关于我们公司网络的 ISA 服务器的,那么我应该进行什么配置ISA Server 不限制我使用外部 Web 服务?
最佳答案
在您的绑定(bind)配置中确保 useDefaultWebProxy
设置为 true - 它将使用您在 IE 中找到的配置。在您的配置文件中添加以下代码段,以确保默认使用您的凭据在代理服务器上进行身份验证:
<system.net>
<defaultProxy useDefaultCredentials="true" />
</system.net>
关于WCF 客户端 - 运行 Web 服务时需要 407 代理身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8723545/