This topic has not yet been rated - Rate this topic

Walkthrough: Creating and Implementing a Custom WCF Service in SharePoint Foundation

SharePoint 2010

Published: May 2010

This walkthrough shows how to create a custom Windows Communication Foundation (WCF) service in Microsoft Visual Studio 2010 that is hosted by Microsoft SharePoint Foundation 2010, and also a Windows Forms Application that implements the service. The application also implements the new SharePoint Foundation client-side object model and the new SharePoint Foundation REST (Representational State Transfer) interface. The walkthrough illustrates how to use the new APIs to interact with site data from remote applications.

The first two parts of this walkthrough involve creating the Windows Form Application to consume the custom WCF service. The first part uses ADO.NET Data Services and the SharePoint Foundation REST interface to retrieve and update items in a list, and the second part uses the client object model to retrieve site data and to modify a list. The third part of the walkthrough shows how to create a WCF service that uses the server object model to restore list items to their previous versions, and how to implement the service in the Windows Forms Application.

The walkthrough assumes the existence of two SharePoint Foundation custom lists: one that is named Projects, and the other named Employees. A Projects column in the Employees list is a lookup to the Title column of the Projects list. In addition to a Title column, the Projects list has Description and Due Date columns. The Employees list has Full Name, Job Title, and Team columns, in addition to the Projects column. The Projects list has item versioning enabled.

Important noteImportant

When a web application is configured to use claims authentication (Windows claims, form-based authentication claims, or SAML claims), the Internet Information Services (IIS) website is always configured to have anonymous access turned on. Your custom SOAP and WCF endpoints may receive requests from anonymous users. If you have code in your WCF service that calls the RunWithElevatedPrivileges method to access information without first checking whether the call is from an authorized user or an anonymous user, you risk returning protected SharePoint data to any anonymous user for some of your functions that use that approach.

NoteNote

Claims authentication is the standard authentication method in SharePoint 2010. For more information about claims, see Claims and Security and Plan Authentication Methods.

Microsoft SharePoint Foundation 2010

SharePoint development tools in Microsoft Visual Studio 2010

Date

Description

Reason

May 2010

Initial publication

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Bug with MultipleBaseAddressBasicHttpBindingServiceHostFactory when not hosted at the Root
Bug with MultipleBaseAddressBasicHttpBindingServiceHostFactory when not hosted at the Root
Bug with MultipleBaseAddressBasicHttpBindingServiceHostFactory when not hosted at the Root
There appears to be a bug in MultipleBaseAddressBasicHttpBindingServiceHostFactory that means that the endpoints generated by that factory are only correct if the site is hosted in the root. e.g. If your site collection is hosted in say /sites/myportal and you deploy your WCF Service there, then the endpoint will be:
http://servername/mycompanyname/_vti_bin/myportal/CommonService.svc   when it should really be
http://servername/mycompanyname/sites/myportal/_vti_bin/CommonService.svc  

When this happens, your service will work (with a valid HttpContext) but the SPContext will be null.

For more information and workarounds, see http://ddkonline.blogspot.com.au/2012/02/sharepoint-2010-when-hosting-wcf.html
Anonymous Access
Thanks to Steve Peschka for the following addition (http://blogs.technet.com/b/speschka/ )

IMPORTANT:
When a web application is configured to use claims authentication (Windows claims, form-based authentication claims or SAML claims), the IIS web site is always configured to have anonymous access turned on. Your custom SOAP and WCF endpoints may receive requests from anonymous users. If you have code in your WCF service that calls the RunWithElevatedPrivileges method to access information without first checking if the call is from an authorized user or an anonymous user, you risk returning protected SharePoint data to any anonymous user for some of your functions that use that approach.

NOTE:
Claims authentication is the defacto authentication method in SharePoint 2010. For more information about claims, see Claims and Security(http://msdn.microsoft.com/en-us/library/gg430136.aspx ) and Plan Authentication Methods (http://technet.microsoft.com/en-us/library/cc288475.aspx).

Posted by: Siew Moi Khor -- MSFT, March 4, 2011
p.s. We're in the process of updating this topic for replublication.
get 415 Http error utf-8 binding mismatch
Hi guys. Tearing my hair out here. Double checked all the code, deploys fine, I see it via the browser with the /MEX URL, can add the service reference to my windows app but it bombs out on the proxy.revert call with
"utf-8 not supported .....client and service bindings may be mismatched.
I've looked in the svc file etc and all look good. Any help would be appreciated.
thanks