Do you remember those DCOM days and the struggle of authenticating over a firewall or proxy server? If you succeeded you were hailed as a hero (but secretly vowed never to do it again). If you failed you could join the hoard of developers disillusioned with distributed computing.
Then along came web services, never again would we have authentication problems.. "everything is plain text over http", distributed programming was viable again and this time it would be easy! Why then has it taken me a day to consume a web service and I'm still not any closer to creating the sodding proxy class! What's my problem you ask...:
There was an error downloading 'zzzzzzzzzzz'.
The request failed with HTTP status 407: Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy service is denied).
AUTHENTICATION!
I spent ages seeing if I could manually enter my proxy information into one of the multitudes of config files but the most I could do was specify in the machine.config that I didn't want to use system default and to specify a proxy address;
<defaultProxy>
<proxy usesystemdefault="false" proxyaddress="[myproxyaddress]" />
</defaultProxy>
No username and password entry !
I then turned to the good old command line (if these things are available on the command line, then why not through VS?) with WSDL.exe. WSDL does allow you to specify the proxy servername, username, password and domain and it look as if it was going to work but now I have another problem;
Error: There was an error processing 'zzzzzz.asmx'.
- There was an error downloading 'zzzzz.asmx'.
- The underlying connection was closed: Unable to connect to the remote server.
Searching the internet I get tantalizing glimpses of what the problem might be but no definitive answer! I know the problem must be to do with my network setup but I though all this was supposed to be easy with web services! If a lot of people have similar problem (as my google searches seem to suggest) then I'm not sure we should be heralding the days of distributed computing!
I'm now going to go home and sulk, then I'm going to try to create the proxy class at home and see if I can copy it into my solution here tomorrow! Apparently once you create the proxy class you can set the authentication properties of the class programmatically!
Follow up
I managed to create the proxy class(using WSDL.exe properly) and then compiled and added a reference to it in my project but when I tried to execute a method on the web service I got an authentication problem again!
However using the following code I managed to solve this.
NetworkCredential nwkCred = new NetworkCredential("username","password","domain");
myProxyClass.Proxy = new WebProxy("proxyaddress",false,null,nwkCred);
myProxyClass.Proxy[.credentials] sets the credentials (login) details for the proxy server you use to get on the internet with. Try not to get confused with the credentials property on the proxy class itself, this sets the login details for the web services.