Posts Tagged ‘Web Services’

WCF Talking to SharePoint Web Services

November 12, 2008

This had nailed me for about 3 days – how to get a Windows Communication Foundation-based call to a SharePoint 2007 Web Service.  Thankfully, there is a solution:

http://blah.winsmarts.com/2008-7-Using_a_WCF_Client_to_talk_to_SharePoint_OOTB_Web_Services.aspx

In particular, I was using:

<security mode=TransportCredentialOnly>
<transport clientCredentialType=Ntlm/>
</security>

in my app.config, which I think was the issue.  Replacing that with:

<security mode=TransportCredentialOnly>
<transport clientCredentialType=Ntlm proxyCredentialType=Ntlm realm=“”/>
<message clientCredentialType=UserName algorithmSuite=Default/>
</security>

and the code change as specified in the blog post fixed everything!  Once again, I am a victim of not knowing enough about WCF security configuration *sigh*  Annoyingly, some web service calls worked, and some didn’t, which made it more difficult to spot the issue.  These worked:

  • SiteData (GetSiteAndWeb)
  • Lists (GetList)

but this one (my important one!) didn’t:

  • Lists (GetListItems)

After I made the config change, all worked perfectly.

 

UPDATE: Two more items to add to this post, the first in particular because I kept on getting exceptions all wrapped up in a FaultException:

“Exception of type ‘Microsoft.SharePoint.SoapServer.SoapServerException’ was thrown.” 

This was particularly annoying because I couldn’t work out any way to get the underlying exception information.

  1. Adding this line fixed my FaultException problem :
    sharepointServiceClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
  2. Make sure you set the Endpoint address to the site you want to interrogate.  Usually this means adding a line similar to:
    listsClient.Endpoint.Address = new EndpointAddress(webInfo.SiteUrl + “/_vti_bin/lists.asmx”);
    otherwise you will probably just get FaultExceptions / SoapServerExceptions and not be able to work out why!