2

I'm developing a SharePoint Timer Job to geocode some lists of addresses held on our SharePoint site.

I'm using code based on this MSDN sample to do the actual Geocoding request.

The problem I get is that when I call the service from SharePoint 2010 (running locally) I get a 401 unauthorised error in return.

Interestingly, I have also created a small winforms application which does the same thing (but without SharePoint/IIS) using the same code which works perfectly.

I'm setting the credentials the same way on both apps as follows:

request.Proxy.Credentials = CredentialCache.DefaultCredentials;

I'm an enterprise user and I'm using the same key on both apps - but one works and one doesn't - any ideas why this might be? Is it something i need to set in IIS perhaps?

I tried setting Pipelined = false on the request which was a suggestion I read about on but that didn't seem to work.

Any suggestions gratefully accepted.

Neysor
  • 3,893
  • 11
  • 34
  • 66
Tim
  • 163
  • 1
  • 1
  • 10
  • 1
    Perhaps SharePoint is not passing the same credentials... It is after doing an impersonation. See if Fiddler can record which user is being used. – Nat Mar 05 '12 at 21:20
  • Thanks Nat - The SharePoint application was using a service account which turned out not to have permissions to access the proxy. I switched it to use my admin account and it immediately started working. Now all I need to do is convince Infrastructure to grant permissions to my service account! – Tim Mar 06 '12 at 08:40

1 Answers1

1

Looks like you solved it by changing the identity of the application pool.

The other way to do it is to say that the web service call should be made using the identity of the user that sent the request to SharePoint. To do that try something like:

 using (((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate())
 {
    WCFTestService.ServiceClient myService = new WCFTestService.ServiceClient();
    Response.Write(myService.GetData(123) + "<br/>");
    myService.Close();
 }
Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252