I need to create a Sharepoint web serivce at work. I follow the instructions from here but found it too long to read so I want to summarize the steps in here:
1. Create the web service. Register the dll into GAC by using gacutil /i dllname.dll. (If I don’t register dll into GAC it’s not working. I will just leave it for now and will investigate later).
2. Create the disco and wdsl file using this command from VS.Net command prompt:
Disco http://server_name:New_Port/Project_Name/Service_1.asmx
3. Rename service1.disco to service1disco.aspx. Open the file and replace this line:
<?xml version=”1.0″ encoding=”utf-8″?>
to:
<%@ Page Language=”C#” Inherits=”System.Web.UI.Page”%> <%@ Assembly Name=”Microsoft.SharePoint, Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %> <%@ Import Namespace=”Microsoft.SharePoint.Utilities” %> <%@ Import Namespace=”Microsoft.SharePoint” %>
<% Response.ContentType = “text/xml”; %>
4. Rename Service1.wsdl to Service1wsdl.aspx and do the same thing to the file
5. Open Service1disco.aspx and locate
<contractRef ref=”http://server_name:New_Port/Project_Name/Service1.asmx?wsdl” docRef=
“http://server_name:New_Port/Project_Name/Service1.asmx” xmlns=”http://schemas.xmlsoap.org/disco/scl/” />
Change that to
<contractRef ref=<% SPEncode.WriteHtmlEncodeWithQuote(Response, SPWeb.OriginalBaseUrl(Request)
+ “?wsdl”, ‘”‘); %> docRef=<% SPEncode.WriteHtmlEncodeWithQuote(Response,
SPWeb.OriginalBaseUrl(Request), ‘”‘); %> xmlns=”http://schemas.xmlsoap.org/disco/scl/” />
6. Locate the tag:
<soap address=”http://server_name:New_Port/Project_Name/Service1.asmx” xmlns:q1=
“http://tempuri.org/” binding=”q1:Service1Soap” xmlns=”http://schemas.xmlsoap.org/disco/soap/” />
and change it to
<soap address=<% SPEncode.WriteHtmlEncodeWithQuote(Response, SPWeb.OriginalBaseUrl
(Request), ‘”‘); %> xmlns:q1=”http://tempuri.org/” binding=”q1:Service1Soap” xmlns=
“http://schemas.xmlsoap.org/disco/soap/” />
7. Open Service1wsdl.aspx and locate
<soap:address location=”http://server_name:New_Port/Project_Name/Service1.asmx” />
Change it to
<soap:address location=<% SPEncode.WriteHtmlEncodeWithQuote(Response,
SPWeb.OriginalBaseUrl(Request), ‘”‘); %> />
8. Copy the Service1wsdl.aspx file, the Service1disco.aspx file, and the Service1.asmx file to c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI directory
9. Open c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI directory\spdisco.aspx. Add the following line to the end of the file within the discovery element:
<contractRef ref=<% SPEncode.WriteHtmlEncodeWithQuote(Response, spWeb.Url + /_vti_bin/Service1.asmx?wsdl”,
‘”‘); %> docRef=<% SPEncode.WriteHtmlEncodeWithQuote(Response, spWeb.Url + “/_vti_bin/Service1.asmx”, ‘”‘);
%> xmlns=”http://schemas.xmlsoap.org/disco/scl/” /><soap address=<%
SPEncode.WriteHtmlEncodeWithQuote(Response, spWeb.Url + “/_vti_bin/Service1.asmx”, ‘”‘); %>
xmlns:q1=”http://schemas.microsoft.com/sharepoint/soap/directory/” binding=”q1:Service1Soap”
xmlns=”http://schemas.xmlsoap.org/disco/soap/” />
where binding=”q1:Service1Soap” specifiies the name of the class defined in the web service
10. try running the web service by entering http://sharepointserver_name:port/_vti_bin/Service1.asmx on the web browser.
Note:
1. When re-register gac, you have to restart IIS by typing iisreset
2. To debug web serivce locally from Visual Studio. Attach the the project to the workerprocess – w3wp.exe.