Using Web Services in C #: Basic Authentication and Dynamic Endpoint URL

I am trying to call a soapy web service from C #. With a static URL and without authentication, everything works fine. I used wsdl and csc to create the dll, and also worked with web links. This moment was the easy part.

For a dynamic URL, I saw http://www.codeproject.com/KB/XML/wsdldynamicurl.aspx , but this is from 2005, and I don't know if this is deprecated. Is using "normal" links right?

My web service uses basic authentication, but I cannot figure out how to provide the user / password.

I have already seen http://benpowell.org/supporting-the-ws-i-basic-profile-password-digest-in-a-wcf-client-proxy/ , but it looks very complicated, and I hope that will be easier to implement basic authentication.

+4
source share
1 answer

To implement basic authentication for your web request, you will have to use NetworkCredential for your request.

NetworkCredential creds = new NetworkCredential(user,password); WebRequest req = WebRequest.Create(Url); req.Credentials = creds; 

If you use a web link to access a web service; while you are creating your proxy class object, just assign credentials to it.

 NetworkCredential creds = new NetworkCredential(user,password); proxy.Credentials = creds ; //call your web methods here. 

For a dynamic URL, the article you mentioned should work.

+3
source

Source: https://habr.com/ru/post/1386477/


All Articles