views:

27

answers:

1

Is there a nice and tested piece of code out there that I can use for this purpose:

get the user/pass and the address of a web service (asmx page) and check if the user/pass are valid or not.

I think I should use HTTPRequest,etc to do that but I do not have a good knowledge on that topic , causing my current method to not working properly.

If there is a good piece of code for this purpose I appreciate for pointing me to that.

Thanks

P.S: I am not using DefaultCredentials in my code. Since I want them to enter user/pass so now I need to be able to TEST their user/pass and show proper message to them if their credentials is not valid.

A: 

You can use the HttpWebRequest.Credentials Property (depends on the web service authentication) and the CredentialCache Class.

Also some code examples (from google):
Retrieving HTTP content in .NET
Combine Invoking Web Service dynamically using HttpWebRequest with .Credentials.

Jaroslav Jandek
yeah Thanks, I saw that page you had posted but in its example it is doing this: " request.Credentials = CredentialCache.DefaultCredentials; " which is Not what I need. I need to "Test" the user/pass that users have entered.
BDotA
Use your own instance of `CredentialCache` instead (added a link so you see how).
Jaroslav Jandek
I do not have problem with "setting" my credentials. Just I want a simple method that does this: gets a user name, a password, a asmx page addresss and determines if this user/pass is correct or not. That's it and I do not see it anywhere in the pages you posted. Thanks tho.
BDotA
What's the problem? Create a form or a console application. A `TextBox` and `Button` or `Console.ReadLine();` to get input from the user and pass it to the code using `CredentialCache` for credentials (username, password) and `HttpWebRequest` with the URL you got from user... What more do you need? If it returns OK, you can access the service, if not, you get a 401 status code back => not able to login...
Jaroslav Jandek