C#WCF - (407)需要代理身份验证(Forefront TMG需要授权才能完成请求。拒绝访问Web代理筛选器

时间:2016-11-17 08:20:55

标签: c# .net wcf proxy

我们正在尝试使用ConfigurationChannelFactory建立WCF服务连接。

这是示例代码。

private void OpenGateWayServiceConnection()
        {
            try
            {
                string gateWayEndPointAddress = "URI";    
                String physicalfilePath = "GateWayService.config"

                ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();                     

                fileMap.ExeConfigFilename = physicalfilePath;
                Configuration newConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

               _channelFactory = new ConfigurationChannelFactory<IMyContract>(
                        "GateWayServiceEndPoint",
                        newConfiguration,
                        new EndpointAddress(gateWayEndPointAddress));

                ((BasicHttpBinding)_channelFactory.Endpoint.Binding).UseDefaultWebProxy = true;
                ((BasicHttpBinding)_channelFactory.Endpoint.Binding).ProxyAddress = HttpWebRequest.GetSystemWebProxy().GetProxy(new Uri(gateWayEndPointAddress));

                _client = _channelFactory.CreateChannel();
            }
            catch (CommunicationException)
            {
                Close();
            }
        }

绑定配置:

<basicHttpBinding>
        <binding name="GateWayService_BasicHttpbinding" closeTimeout="00:05:00" openTimeout="00:05:00" receiveTimeout="00:10:00"
            sendTimeout="00:05:00" transferMode="Streamed" useDefaultWebProxy="true" maxBufferPoolSize="2147483647"
            maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Mtom">
            <readerQuotas maxBytesPerRead="65536" maxArrayLength="2147483647"/>  
        </binding>
        <binding name="GateWayServiceEndPoint" messageEncoding="Mtom" />
        <binding name="BasicHttpBinding_IMyContract" />
      </basicHttpBinding>

当我们尝试使用公开的方法时,_client.SayHelloWorld();

(407)抛出所需的代理验证。

为什么WCF客户端没有使用默认代理设置?

如果我们更改连接设置选项 - &gt;设置 - &gt;连接设置为自动检测代理设置,它正在工作。

0 个答案:

没有答案