我正在托管 WCF Web 服务(在 Azure 上),并将 WPF 桌面应用程序发送给(显然)尝试通过代理访问该服务的客户端。
服务调用失败,返回
The remote server returned an unexpected response: 407 Proxy Authentication Required
客户端 app.config 文件的 ServiceModel
部分如下所示:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ILicensing" closeTimeout="00:00:15" openTimeout="00:00:15"
receiveTimeout="00:00:15" sendTimeout="00:00:15" maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="xxxxxxx"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ILicensing"
contract="Cloud.ILicensing" name="BasicHttpBinding_ILicensing" />
</client>
</system.serviceModel>
我所知道的基本上就这些了。
我想通过修改服务的 app.config 文件和/或 web.config 文件来修复此行为(这应该不重要,因为无论如何都无法访问该服务)。
据我了解,绑定(bind)节点有一个属性useDefaultWebProxy
,它要求查找系统代理配置并使用它来连接到服务。但是,由于默认值为 true
,我希望将其显式设置为 true
不会改变任何内容(我猜这基本上是默认值的定义)。
考虑到
useDefaultWebProxy
未设置,因此由于其默认值应为true
,代理身份验证失败的原因可能是什么?考虑到有限的信息,如何修改app.config以解决问题?基本上:我需要知道/询问我的客户端什么(即代理服务器地址)以及我需要在客户端配置文件中的何处插入信息?
如何在本地计算机上设置模拟该问题的测试环境?
最佳答案
对于 1 和 2,您需要配置 System.Net
为默认代理提供默认凭据 - 它不会默认情况下是这样(因为自动访问互联网的应用程序中隐藏的回调代码会很糟糕)。
<system.net>
<defaultProxy useDefaultCredentials="true" />
</system.net>
对于 3,我不完全确定如何在本地测试它,因为您需要一台计算机充当代理,而这些计算机通常是域 Controller 类型的计算机。您可以使用 2 个虚拟机进行模拟,但我希望您有一台功能强大的机器来做到这一点,而且测试这一点似乎需要付出很大的努力。
关于c# - WCF服务调用返回 '407 Proxy Authentication Required',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28562546/