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:
- 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)
- 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
- 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)
- 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.
- 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
- 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) and stop until “To copy the Web service files to the _vti_bin virtual directory”).
- 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:
- <service>.asmx , where <service> is your web service file.
- <serviceDISCO>.aspx , where <serviceDISCO> is corresponding DISCO file of your web service.
- <serviceWSDL>.aspx , where <serviceWSDL> is corresponding WSDL file of your web service.
- 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.
- 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.
- Create HttpHandler to combine content of spdisco.aspx and *.spdisco.aspx.
- Register HttpHandler in web.config. We will intercept all _vti_bin/spdisco.aspx with our HttpHandler.
- Tutorial video, Writing Custom Web Services for SharePoint in Supported Mode.
- Download source code for this article Visual Studio 2010 + SharePoint 2010 (http://code.msdn.microsoft.com/Writing-SharePoint-Web-in-cb9de1be)