开发者

Attempting to call an external webservice from ASP.NET returns a 401 - DefaultCredentials empty

开发者 https://www.devze.com 2022-12-28 21:05 出处:网络
Fails: //Note: webserviceProxy inherits from SoapHttpClientProtocol //App Pool is running as a user with permissions to call the external webservice

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's credentials to the webservice proxy's 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 the identtity of ASP.NET's app pool? There doesn't seem to be a way to convert System.Security.Principal.WindowsIdentity.GetCurrent() to something I can use for this call.

Thanks!


Maybe this Microsoft support article can help you solving the issue:

You receive error 401.1 when you browse a Web site that uses Integrated Authentication and is hosted on IIS 5.1 or a later version

The bottom line is that Windows will protect itself when the machine name and web site FQDN do not match.

Also see:

  • http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/a93e5074-a06f-46e2-af82-c743a9ac96b4/
  • http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/ac38e0da-c828-48b8-aa3f-fb22f30ce581
0

精彩评论

暂无评论...
验证码 换一张
取 消