Saturday, September 12, 2009

Sharepoint WebService Deployment Routine

Follow the steps for deploying ASP.Net Webservices to Sharepoint environment.
1. Run the ASP.Net Webservice from Visual Studio (Hit F5).
2. Copy the URL from the browser.
3. Open Visual Studio Command Prompt.
4. Go any Folder using DOS Command
5. Type the Command DISCO http://servername:portnumber/WebServiceName.asmx ( URL Copied in Step 2)
6. This will generate the discovery (.disco) file and the WebService Definition (.wsdl) file to the Current Folder.
7. Rename the .disco and .wsdl to WebServiceNameDisco.aspx and WebServiceNameWsdl.aspx
8. Replace the header of the (files mentioned in Step 7) .aspx files to use ASPX page header tags
<%@ Page Language="C#" Inherits="System.Web.UI.Page" %> <%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint.Utilities" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
9. Replace the webservice url references inside the file to use Server tag which builds the Dynamic WebUrl at request time.
Remove the localhost link to the wsdl and asmx uri with
<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request) + "?wsdl"),Response.Output); %> for wsdl
and <% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> respectively
10. Open the .asmx file in some text editing tool (notepad for eg.) and replace the CodeBehind to use the Respective class and the Dll name space.
<%@ WebService Language="C#" Class="NameSpace.ClassName, NameSpace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=dllkeytoken" %>
where NameSpace is your dll namespace, ClassName is the WebService class name and dllkeytoken is the public ket token of dll. 11. Copy WebServiceName.asmx, WebServiceNameDisco.aspx and WebServiceNameWsdl.aspx to ISAPI Folder in the 12 Hive.
12. Test the WebService Request by typing the WebService Request as follows, http://sharepointurl/_vti_bin/WebServiceName.asmx.

Note: The WebService can be debugged in Visual Studio (if dll Deployed is in Debug Mode) by attaching it to the w3wp.exe process.

No comments: