Attempting to call an external web service from ASP.NET returns 401 - DefaultCredentials empty

Fails:

//Note: webserviceProxy inherits from SoapHttpClientProtocol //App Pool is running as a user with permissions to call the external webservice var webserviceProxy = new webServiceProxy(); webserviceProxy.PreAuthenticate = true; webserviceProxy.UseDefaultCredentials = true; var returnVal = webServiceProxy.DoSomething(); //Fails with 401, webserviceProxy.Credendials shows an empty username, pass, and domain 

Works:

 //This code works, but I want to assign the current app pool credentials to the webservice proxy credentials. UsingDefaultCredentials doesn't work. The username, passoword, and domain are always null. var webserviceProxy = new webServiceProxy(); webserviceProxy.PreAuthenticate = true; webserviceProxy.Credentials = new NetworkCredential("user", "pass", "domain"); var returnVal = webServiceProxy.DoSomething(); //Fails with 401 

How can I make an external webservice call using an ASP.NET application pool identifier? There seems to be no way to convert System.Security.Principal.WindowsIdentity.GetCurrent() into what I can use for this call.

Thanks!

+4
source share
1 answer
+3
source

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


All Articles