jarleberge
asked on
Basic Authentication of Web Services
I'm using C# / Visual Studio to access a web service. The service requires basic authentication to show its' available operations. Passing the username and password to it works well. Adding the reference to my project does also work well. But when accessing operations in my code, I get a 401 error, saying "Invalid authentication".
So, my question: How do I configure my service to pass the username and password at runtime?
So, my question: How do I configure my service to pass the username and password at runtime?
ASKER
Thank you!
I'm not a very experienced .NET programmer, so I can sketch up my approach in some steps here:
1) Adding a Web Reference in my Visual Studio by giving the adress of the WSDL
2) I'm provided to give a username and password
3) A list of operations appears and I give the reference a name and add it
4) I use the reference directly in my code calling the operations with neccesary parameters and handling the result.
The problem comes at step 4), when running it. How can I actually make the proxy to let it handle username and password for the operation/method calls. Do you have any more explaining code?
I'm not a very experienced .NET programmer, so I can sketch up my approach in some steps here:
1) Adding a Web Reference in my Visual Studio by giving the adress of the WSDL
2) I'm provided to give a username and password
3) A list of operations appears and I give the reference a name and add it
4) I use the reference directly in my code calling the operations with neccesary parameters and handling the result.
The problem comes at step 4), when running it. How can I actually make the proxy to let it handle username and password for the operation/method calls. Do you have any more explaining code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If so you can edit that class and add fields for the username and password that can be set either using accessor methods or from a constructor.
or you can do it on the fly by creating an instance of your proxy class but before you call ant of its methods you set its credentials :
proxyclass.Credentials = new NetworkCredential(username