I am working on a project that has two parts, a WCF application, which is hosted on IIS. This application is consumed by another application but desktop.
The applications work perfectly, both in the development environment and in a production environment (connecting to the server through a public ip). The drawback I'm having is that we just started with a client, whose network has a proxy, which causes us to use the following error when it comes to consuming some WCF method:
The remote server returned an unexpected response: (407) authenticationrequired.
After this, I started to investigate, until I found that the proxy should be configured in binding
, so guiding me with a post that I found I developed the following code:
private static ConnectivityClient getProxy()
{
ConnectivityClient client = new ConnectivityClient();
var useProxy = Boolean.Parse(Util.GetAppSettings("useProxy")); //determina sí ocupa configuración proxy o no.
var proxyAddress = Util.GetAppSettings("proxyAddress"); //define la dirección del proxy
var proxyPort = Util.GetAppSettings("proxyPort"); //define el puerto del proxy
if (useProxy)
{
var b = new BasicHttpBinding();
b.ProxyAddress = new Uri(string.Format("http://{0}:{1}", proxyAddress, proxyPort));
b.UseDefaultWebProxy = false; // !!!
b.Security.Mode = BasicHttpSecurityMode.None;
b.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; // !!!
b.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None; // !!!
b.BypassProxyOnLocal = false;
client.Endpoint.Binding = b;
}
client.Endpoint.Address = new System.ServiceModel.EndpointAddress(getURL());
return client;
}
Now, it still does not work, because in case you set the BasicHttpSecurityMode
in None
it throws me again the authentication error, if I configure it as Transport tells me that it occupies HTTPS (which the server of the WCF does not have) and any other type asks for credentials.
According to what I have read, this is a problem merely on the client's side and has no relationship with the WCF, nor with the IIS.
If someone could help me know how to configure the proxy and also configure credentials as anonymous. Thank you very much.