views:

16

answers:

1

I wrote this method to test for credentials but I dunno why when it goes to the GetResponse method is actually goes and runs the webservice. I just want it to test if the credentials for that web service are correct or not.

   private bool TestCredentials(string sURL, ref  string sUsername, ref  string sPassword)
    {

        bool retVal = false;
        CredentialCache myCache = new CredentialCache();
        myCache.Add(new Uri(sURL), "Full", new NetworkCredential(sUsername, sPassword, "our_domain"));

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sURL);
        request.Credentials = myCache;
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        if (response.StatusCode == HttpStatusCode.OK)
            retVal = true;
        return retVal;
A: 

You can't know if the credentials are good without some kind of communication with the server. You could create a dummy URL to execute a test request against. IE, an URL you can request that doesn't actually do anything on the server.

Tim Coker
dummy URL? you mean instead of passing the real asmx address, I pass for example http://www.google.com ? but still with the same credentials? but if you mean another url on that server, well this is the only url that we have at all.
BDotA
Do you have any control over the server? If you don't, there's not a lot you can do. Making the request (IE, calling `GetResponse`) will execute the action. What I was meaning was adding another function to the webservice that doesn't do anything.
Tim Coker