WCF Talking to SharePoint Web Services

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:


In particular, I was using:

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

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/>

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!

Tags: , ,

One Response to “WCF Talking to SharePoint Web Services”

  1. Alexey Says:

    Thank you! You saved a lot of my time

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: