If you get the “Type cannot be found” error after installing your WCF service, go to the section about unloading your project below.

Here are the main steps to creating a WCF service and installing it on a SharePoint 2010 server:

  1. Open Visual Studio 2010
  2. Create an Empty SharePoint 2010 project to get the packaging files
  3. Change your namespace in the Project Properties.
  4. Add a new Item, WCF Service with a new file name
  5. Add the following lines above the class declaration that implements the “IService” file:

[BasicHttpBindingServiceMetadataExchangeEndpointAttribute]

[AspNetCompatibilityRequirementsAttribute(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]


public
class
PricingRequestService : IPricingRequestService

{

  1. Add the following references to your project:
    1. C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14ISAPIMicrosoft.SharePoint.dll
    2. C:WindowsassemblyGAC_MSILMicrosoft.SharePoint.Client.ServerRuntime14.0.0.0__71e9bce111e9429cMicrosoft.SharePoint.Client.ServerRuntime.dll
  2. Add a mapped folder to the “_Layouts” folder
  3. Inside the _Layouts folder create a text file with a .svc extension such as PricingRequestService.svc

Add the following sample: <%@ServiceHost
Language=”C#” Debug=”true”


Service=”PricingRequest.PricingRequestService, $SharePoint.Project.AssemblyFullName$”


Factory=”Microsoft.SharePoint.Client.Services.MultipleBaseAddressBasicHttpBindingServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”
%>

  1. Change the namespace and service name to your own. Leave the public key token alone as it refers to the ServerRuntime dll.

http://msdn.microsoft.com/en-us/library/ff521581(v=office.14).aspx

Gotcha from MSDN:

Make sure to Unload your project and add this to the project file:

<TokenReplacementFileExtensions>svc</TokenReplacementFileExtensions>

Just above </PropertyGroup>

 

Because Visual Studio 2010 by default does not process the type of tokens used in the previous .svc file, you must add an additional instruction in the project file. Save all changes in your project, right-click the RevertService project, and then click Unload Project. Right-click the RevertService node again, click Edit RevertService.csproj or Edit RevertService.vbproj, and add a <TokenReplacementFileExtensions> tag as follows to the first property group in the .csproj or .vbproj file to enable processing of tokens in .svc file types.


  1. Package your project to get your .wsp package
  2. Run the following Powershell commands to add/install the solution
    1. Add-SPSolution “i:YourPathPricingRequestCP.wsp”
    2. Install-SPSolution -Identity PricingRequestCP.wsp –GACDeployment
  3. Verify your dll is in the GAC and your .svc file is in the _Layouts folder in a subfolder.
  4. To undeploy your solution, run these Powershell commands:
    1. Uninstall-SPSolution -Identity PricingRequestCP.wsp -Confirm:$false
    2. Remove-SPSolution -Identity PricingRequestCP.wsp -Confirm:$false