SharePoint 2007 (WSS 3.0) and Custom Web Services

SharePoint (MOSS 2007/WSS 3.0) can prove to be quite a chore at times and custom web services are no exception. I view custom web services and their deployment within a SharePoint/WSS environment in two ways. The first, and certainly easiest way is to create a new virtual directory is IIS under the root of your site. While this works, in many cases this might not be preferable. Perhaps we want to put a service in the “Layouts” directory so it is accessible from each site collection and the collection’s sub sites.

To accomplish a “Layouts” deployment, follow the following steps:

  1. Create your web service locally referencing the necessary SharePoint libraries (Microsoft.SharePoint.dll and Microsoft.Office.Server.dll)
    1. If you plan on deploying your compiled library to the GAC on your servers, be sure to generate a strong name and change the project settings to use it.
    2. The libraries above can be found at “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI”
    3. I recommend using a Class Library or a Web Application project to make compiling slightly more sane later on.
  2. Once your service is built and can be accesed locally (either through the built-in web server or IIS), we can deploy it to it’s target environment. If you have used a Web Application Project, you can now publish your site to either a separate directory on your local drive or directly to the SharePoint server.
  3. Copy your service and any associated files (controls, web pages, web.config, etc.) to your destination server to the following directory:
    “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\<Service Name>”

    1. Do not copy your bin folder or it’s contents to this location.
  4. Take your libraries from your compiled project (contents of the “bin” directory) and deploy them to the target server root directory. You can determine this directory from IIS. (Example: “C:\inetpub\wwwroot\VirtualDirectories\80\bin”)

After following the steps above, you should now be able to browse to your service. The beauty of a “Layouts” deployment is that your service will now be accessible from each and every site within your web application. I do not do “_vti_bin” deployments in order to keep the core SharePoint files segregated from any custom work of my own, but the methodology used here would apply just the same if you felt inclined to do so.

Image a SharePoint site http://myfakesite/ with the following structure:

  • sites
    • site1
    • site2
  • anothercollection
    • site1

Using the structure above, our custom service could be referenced in the following manner:

  • http://myfakesite/sites/site1/_layouts/<Service Name>/<Service Name>.asmx
  • http://myfakesite/sites/site2/_layouts/<Service Name>/<Service Name>.asmx
  • http://myfakesite/anothercollection/site1/_layouts/<Service Name>/<Service Name>.asmx

With this deployment scenario, our custom service can now perform actions in the current context of a site (Microsoft.SharePoint.SPContext).

And that’s it. Get deploying! While your first deployment might go smoothly, your subsequent deployments will most likely require a quick “iisreset” from the command prompt.

If you feel so inclined, you can compare with the ever popular MSDN instructions, although I prefer mine.

Bookmark and Share
Leave a comment

0 Comments.

Leave a Reply


[ Ctrl + Enter ]

Performance Optimization WordPress Plugins by W3 EDGE