Using a web service through an Internet proxy using a WCF client in C #; providing proxy authentication

I have a client program that uses a web service. It works quite well in a number of installations. Now I have a situation where a new client connects to the Internet through a proxy server, and my program attempt to access the web service receives the message "HTTP status 407: Proxy authentication required".

I thought that all the settings for Internet access, including the proxy server address, port number and authentication, would be done in the settings of the control panel of the control panel, and I would not have to worry about this in the code or even in app.config, the web service client .

Did I get it wrong?

What I did on average gives the user the ability to configure the proxy user name and password, and then in my code I do the following:

webServiceClient.ClientCredentials.UserName.UserName = configuredUsername; webServiceClient.ClientCredentials.UserName.Password = configuredPassword; 

But I do not know what is right. Since it seems to me that the aforementioned ClientCredentials will refer to the binding / security of the web service, and not to the Internet proxy.

I suppose I can try it from a client, but I would rather be sure what I do first.

+6
authentication web-services proxy internet-connection
source share
1 answer

I learned how to do this, with the help of a contributor to another forum, which is trying in a flurry of all kinds of things that I forgot. So thanks to this forgotten man.

Here's the code that worked at the end (suitably masked, but gives the right idea):

  BasicHttpBinding binding = new BasicHttpBinding("APISoap"); /* APISoap is the name of the binding element in the app.config */ binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic; binding.UseDefaultWebProxy = false; binding.ProxyAddress = new Uri(string.Format("http://{0}:{1}", proxyIpAddress, proxyPort)); EndpointAddress endpoint = new EndpointAddress("http://www.examplewebservice/api.asmx"); WebServiceClient client = new WebServiceClient(binding, endpoint); client.ClientCredentials.UserName.UserName = proxyUserName; client.ClientCredentials.UserName.Password = proxyPassword; 
+6
source share

All Articles