SharePoint: Writing Custom Web Service for SharePoint in Supported Mode (part-2)

English Before we continue, I suggest you read the first part here ; it gives basic idea of how it works. The purpose of part-2 is to make real implementation of Custom Web Service , but it is not the only way to do it. There are some key points that I want to show here:

  1. We will put our custom Web Services in a Custom folder under _vti_bin. In this case we will create new folder WSCustom under (12hive/ISAPI for SharePoint 2007 or 14hive/ISAPI for SharePoint 2010)
  2. We will need a helper to read SharePoint context (SPVirtualPath) before passing the request to the real ASMX. In this case we will copy WSDISCO.ASPX  and WSWSDL.ASPX from original _VTI_BIN to _VTI_BIN/WSCustom folder
  3. We will need custom SPDisco.aspx for our web services, in this case I will name it WSCustomSPDisco.aspx. This is the file, where we will register our web service. (Note the registration is optional, but it is required for truly SharePoint integration)
  4. We need an interceptor so that request to SPDisco.aspx will return combination between original SPDisco.aspx and WSCustomSPDisco.aspx. In this case, we will create WSCustomHttpHandler that combine XML from the two files.
  5. We need rules to add rules to redirect request to _vti_bin/spdisco.aspx to our WSCustomHttphandler.

In the diagram, the scenario will look like this image

  1. Create ASPNET Web Services using Visual Studio. You can follow instruction in MSDN here (http://msdn.microsoft.com/en-us/library/dd583131(v=office.11).aspx.aspx”)) and *stop until “To copy the Web service files to the _vti_bin virtual directory”).*
  2. Create custom folder for your project under _vti_bin (for example 12hive/ISAPI/CustomWS for SharePoint 2007 or 14hive/ISAPI/CustomWS for SharePoint 2010). In this custom folder, we will put 3 files for every web service (*.asmx) which are:
    • .asmx , where is your web service file.
    • .aspx , where is corresponding DISCO file of your web service.
    • .aspx , where is corresponding WSDL file of your web service.
  3. Copy ISAPI\spdisco.aspx to ISAPI\spdisco.disco.aspx . We need copy of original spdisco.aspx, since we don’t want to have infinite loop in our HttpHandler later.
  4. Create ISAPI\customws.spdisco.aspx. In this file, we will register our custom web service. This is important to avoid modifying SharePoint built-in file.
  5. Create HttpHandler to combine content of spdisco.aspx and *.spdisco.aspx.
  6. Register HttpHandler in web.config. We will intercept all _vti_bin/spdisco.aspx with our HttpHandler.

More Information

  1. Tutorial video, Writing Custom Web Services for SharePoint in Supported Mode. http://www.youtube.com/watch?v=YBaIJvwmB44
  2. Download source code for this article Visual Studio 2010 + SharePoint 2010 (http://code.msdn.microsoft.com/Writing-SharePoint-Web-in-cb9de1be)
Avatar
Riwut Libinuko
Sr. Cloud Solution Architect

My research interests include distributed robotics, mobile computing and programmable matter.

comments powered by Disqus

Related