Add header (usernametoken) to web reference C #

0

Good evening,

Add a web service as web reference, and I need to create the header with the authentication (Password and username), I do it when I add a Service Reference, but with a web reference no. Can someone help me, please?.

I have read about Microsoft.Web.Services2.Security.Tokens but I do not know if I can do it with visual studio 2013, ps I have not managed to add it.

I'm working with Visual Studio 2013 C #

Thank you, Good evening.

    
asked by afar1793 18.11.2017 в 03:09
source

1 answer

1

Assuming that your web service is configured to work with basic authentication. With this type of authentication, the client (that is, your program) passes the credentials to the webservice, for example:

localhost.Service1 webService = new localhost.Service1();
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential()
{
    Domain = "tu-dominio",
    UserName = "tu-usuario",
    Password = "tu-password"
};
webService.Credentials = credentials;
string result = webService.HelloWorld();
    
answered by 18.11.2017 / 12:29
source