Click here to Skip to main content
15,911,707 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, sorry for my translation, I hope you understand, at the moment I am making the consumption of a webservice from an application developed in c #. The consumption from the SoapUI program is achieved successfully, activating a preference that is called, preventive authentication, its user and password are configured in the tab called "Auth".
However, when I try to send a header with the user and the password returns the error "(500) Internal error of the server", the webservice associates it with the project as a web reference, as recommended by one of the pages in which I found a solution .


What I have tried:

*So far, I associated the WS to the project as a service reference and as a web reference.
*I added the following lines of code to send in the header the credentials and thus recreate the preventive authentication.
string auth = "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(wsParams[0] + ":" + wsParams[1]));
                req.PreAuthenticate = true;
                req.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested;
                req.Headers.Add("Authorization", auth);
                WebResponse resp = req.GetResponse();


*After obtaining the answer (500), I tried to recreate by SoapUI the user and password in the header, without success. Which brings me to the second code test.
*Try to send the authentication using the credentials property from the previous code, but in the same way I get the answer (500)

NetworkCredential networkCredential = new NetworkCredential(wsParams[0], wsParams[1]);
				req.Credentials = networkCredential;
                req.PreAuthenticate = true;
				WebResponse myWebResponse = req.GetResponse();


From here on I have tried almost everything but still can not get the consumption of the ws by code, I would greatly appreciate an idea of ​​how I can make the consumption.
Be attentive
Posted
Updated 18-Jun-18 2:12am

1 solution

// Create the network credentials and assign
// them to the service credentials
NetworkCredential netCredential = new NetworkCredential("wsParams[0]", "wsParams[1]");
Uri uri = new Uri(service.Url);
ICredentials credentials = netCredential.GetCredential(uri, "Basic");
service.Credentials = credentials;

//  set PreAuthenticate to true
// authentication will not be sent.
service.PreAuthenticate = true;


------------
Using req.credentials gives problem with WebMethods because the header part doesnt contain even Preauthentication is set to true So it returns
500 Internal Server Error

request.Credentials = new NetworkCredential(username,password)."



Calling web services using basic authentication - IntelliTect[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900