Deploying WCF EndPoints as solutions in SharePoint 2007

Posted on 9/8/2008 @ 9:10 PM in #SharePoint by | Feedback | 8204 views


Table of contents

- Basics -

1. Create a WCF Home. This is the virtual directory that will host all your WCF endpoints.

2. Create a WCF Service Library, and throw it in the GAC.

3. Create a relevant .svc file in the WCF home you created in step #1.

4. Write a WCF Virtual Path Provider, and register it in the SharePoint site.

 

- Real world -

1. Adding WCF Support to a website.

2. Deploying WCF EndPoints as solutions.


All new functionality must be added to your SharePoint 2007 farm using solutions. WCF EndPoints are no different.

Here is how you can add WCF endpoints neatly packaged as solutions to your SharePoint farm.

1. Enable WCF support on your website.

2. Start with the WCF service library you were working in Step #2.

Add the following folder structure as shown below:

3.  Put the following code in your install.bat

   1:  
   2: @SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm"
   3: @SET WSPPBUILDER="c:\code\WspBuilder\WspBuilder.exe"
   4:  
   5: @echo off
   6: Echo Creating Solution Package
   7: %WSPPBUILDER% -outputpath solution
   8:  
   9: Echo Retracting Solution
  10: stsadm -o retractsolution -name HelloWorldSVC.wsp -immediate
  11: stsadm -o execadmsvcjobs
  12:  
  13: Echo Deleting Solution
  14: stsadm -o deletesolution -name HelloWorldSVC.wsp
  15:  
  16: Echo Adding Solution
  17: stsadm -o addsolution -filename Solution\HelloWorldSVC.wsp
  18:  
  19: Echo Deploying solution
  20: stsadm -o deploysolution -name HelloWorldSVC.wsp -immediate -allowGacDeployment
  21: stsadm -o execadmsvcjobs
  22:  
  23: Echo recycling AppPool
  24: %windir%\system32\inetsrv\appcmd recycle AppPool "SharePoint - 4000"

4. Put a call in post build events to call Install.bat .. usually looks like this - cd $(ProjectDir) .. Install.bat

5. CTRL_SHIFT_B to build and deploy, you should see the endpoint deployed as a solution, which you can verify by going to central admin --> operations --> solution management.

This is shown as below:

That's basically it! Now you can retract/deploy it from all web front ends, and use it easily inside other applications or within SharePoint.

NEAT!

Sound off but keep it civil:

Older comments..


On 8/19/2009 3:35:36 PM super_b said ..
So web service solutions should be deployed at the Farm level, right?


On 8/29/2009 3:37:43 AM H.Y. said ..
First of all. AWESOME series of posts - there is a surprisingly small amount of info out there on how to work with custom wcf services in SharePoint out there so mucho kudos for putting this out there.

Obviously, the Hello World example is somewhat trivial. I was wondering - are there any gotchas for making sure that all the usual SharePoint context is there? Apart from <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> stuff and all that.


On 8/31/2009 4:55:21 AM Dennis Jansen said ..
I can't figure out what the url is of a service deployed this way.


On 9/10/2009 6:04:39 PM Craig said ..
I followed your article which was really helpful. However, I am not able to get SPContenxt.Current. Does anyone have any issues with the same thing I am experiencing?

If so and you have a fix - please tweet me @CraigHead.