I faced almost two weeks of pain for this problem on one of our clients, linking our web services.
You need to override System.Net configuration with a custom proxy module that implements IWebProxy
Step 1. Create an assembly (DLL) Step 2. Add the following class to it.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Configuration; namespace MyProjectNameSpace.Utils.WebProxy { public class CustomWebProxy : IWebProxy { public ICredentials Credentials { get { string _proxyUserName = ConfigurationManager.AppSettings["ProxyUserName" ] as string ?? ""; string _proxyPassword = ConfigurationManager.AppSettings["ProxyPassword" ] as string ?? ""; string _useProxyDomain = ConfigurationManager.AppSettings["UseProxyDomain"] as string ?? ""; string _proxyDomain = ConfigurationManager.AppSettings["ProxyDomain" ] as string ?? ""; return String.IsNullOrEmpty(_proxyDomain) ? new NetworkCredential(_proxyUserName, _proxyPassword) : new NetworkCredential(_proxyUserName, _proxyPassword, _proxyDomain); } set { } } public Uri GetProxy(Uri destination) { string _proxyServer = ConfigurationManager.AppSettings["ProxyServer"] as string ?? ""; Uri result = new Uri(_proxyServer); return result; } public bool IsBypassed(Uri host) { return false; } } }
Step 3: Compile into release mode Step 4: access the WCF client project in the DLL. Step 5. Open the Web.Config or App.Config file for the WCF client project and add the following configurations.
<appSettings> <add key="ProxyServer" value="http://192.168.1.254:9099"/> <add key="ProxyUserName" value="dipak.r"/> <add key="ProxyPassword" value="password"/> <add key="UseProxyDomain" value="true"/> <add key="ProxyDomain" value="DOMAINNAME"/> </appSettings>
Add the following section or change it.
<system.net> <defaultProxy enabled="true" useDefaultCredentials="false"> <module type="MyProjectNameSpace.Utils.WebProxy.CustomWebProxy, MyProjectNameSpace.Utils.WebProxy"/> </defaultProxy> </system.net>
source share