WCF Client - 407 Proxy Authentication Required while running webservice
Asked Answered
K

5

15

I've created simple WinForms app that uses free webservice http://www.webservicemart.com/uszip.asmx. But this app fails to use service operation with error:

The remote server returned an unexpected response: (407) Proxy Authentication Required (The ISA Server requires authorization to fulfill the request. Access to the Web Proxy service is denied)

Code that creates proxy and triggers service operation:

ChannelFactory<ServiceReference1.USZipSoap> proxy = new ChannelFactory<ServiceReference1.USZipSoap>("USZipSoap");
ServiceReference1.USZipSoap client = proxy.CreateChannel();
string str = client.ValidateZip("12345");
MessageBox.Show(str);

Is this problem with a network of my company or this is a proxy on the side of webservicemart.com?

I've googled a lot of information on changing configuration files, creating a custom binding, etc. But I feel the lack of more basic understanding...
If this error is about ISA server of our corporate network then what configuration should I make to ISA Server to not restrict me from using external webservices?

Kloman answered 4/1, 2012 at 7:42 Comment(4)
Yes it is problem with proxy in your local network. Show your binding configuration and also check if you have proxy configured in Internet Explorer.Callender
I just prepared my configuration but it was too large to fit comment size and I've faced with restriction saying that I cannot answer my own questions.<br> But anyway... I really have proxy configured in my browser settings.<br> I'v got some progress after I changed useDefaultWebProxy from true to false. And now I have EndpointNotFoundException with message "There was no endpoint listening at webservicemart.com/uszip.asmx that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details."Kloman
And InnerException of type System.Net.WebException with message "The remote name could not be resolved: 'www.webservicemart.com'"Kloman
If you want to add some details to your question (like configuration) you must edit the question and not pass it as comment or answer.Callender
C
43

In your binding configuration make sure that useDefaultWebProxy is set to true - it will use configuration you have found in IE. In your configuration file add following snippet to ensure default your credentials are used for authentication on the proxy server:

<system.net>
  <defaultProxy useDefaultCredentials="true" />
</system.net>
Callender answered 4/1, 2012 at 13:45 Comment(2)
It is interesting to note that this does not seem to be the same as setting the property on the default proxy.Terrazzo
@VincentHubert It is even more interesting to know what is not the same and not have comments hanging thereBoren
P
2

This worked for me... replacing 10.1.0.50 and the port number with your proxy server's IP

  <system.net>
    <defaultProxy useDefaultCredentials="true">
      <proxy usesystemdefault="False" proxyaddress="http://10.1.0.50:8080" bypassonlocal="True" />
    </defaultProxy>
  </system.net>
Prendergast answered 15/3, 2013 at 10:25 Comment(1)
I'm using @Ladislav Mrnka answare, but it worked for me too.Farnesol
T
1

Seems like all the traffic in your company is being redirected through a proxy. Can you browse to the web service from your IE and see its wsdl and invoke the test page to see some results. If that is the case then try adding the below section into your web.config:

<system.net>   
<defaultProxy>     
<proxy proxyaddress="<your proxy address>" bypassonlocal="true" />
</defaultProxy>
</system.net> 

You can find the proxy address from the settings of your IE.

NOTE: When you move to different environments then you need to make sure that its the same case else you need to remove the above configuration.

Tussah answered 4/1, 2012 at 10:20 Comment(2)
Thank you very much for reply. I've just made some progress in solving this problem. I have changed useDefaultWebProxy from true to false and after that it seems like I've passed my proxy authentication. But I still have another exceptions saying that "There was no endpoint listening at webservicemart.com/uszip.asmx that could accept the message." I have also tried another free webservice and just received exactly the same error.Kloman
I have tried accessing the above web service and it works fine. If you need help just post some more update and can try helping you out.Tussah
P
0

You can set the web.config of the service to allow to use the proxy settings as defined in Internet Explorer.

Poliomyelitis answered 26/8, 2013 at 10:1 Comment(0)
B
0

Sometime in the future.

WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
Beira answered 19/9, 2017 at 22:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.