Last post Aug 27, 2013 03:13 PM by SheldonS
Aug 27, 2013 03:10 PM|SheldonS|LINK
I had originally posted this in the
wrong area. I finally figured the initial answer out on my own so I thought I would follow the suggestion of posting it here. I am certain some of the users here can fill in the finer details for me. I'll put my oringal post and then I will put what
I feel is an "initial answer". I say "initial answer" because yes it works but I don't think it is the best way to do it.
First my original post:
I have used the WSDL tool before to create a proxy class for a web service that is not hosted on IIS. I now have to use one that requires a user name and password in the
SOAP request properties. This authentication is not part of the web methods, but part of accessing the URL for the methods.
My question is how do I supply that information?
Aug 27, 2013 03:13 PM|SheldonS|LINK
After some vacation and asking a friend, I finally figured it out. Like anything it seems so easy.
O.K. In the proxy class that the wsdl tool generates I saw I could access this.Credentials. It is an object that expects something that implements System.Net.ICredentials.
So I created a new class which implemented this ICredentials interface which I will call ProxyCreds. I left its constructor empty and used Implement Interface Explicitly to create the methods I needed. Turns out there is only one. This method takes a
URI and a string as parameters, but I did not use them. I might if I can find where to set those globally in the proxy class, but for now, setting the username and password in this one method will suffice.
/// Class to provide credentials
/// for the web service
public class ProxyCreds : ICredentials
NetworkCredential ICredentials.GetCredential(Uri uri, string authType)
//TODO Set the user and password
return new NetworkCredential("userName", "passWord");
In the constructor for the proxy class I create a new instance of my class (ProxyCreds) that implements ICredentials. Then I set this.Credentials equal to that instance.
In my case it worked. I'm sure there is a better way to do this, but it is a start.