How To: Steps to create web services in MOSS 2007
I followed the article https://msdn2.microsoft.com/en-us/library/ms464040.aspx but still I had to do couple of more settings which I have covered here.
A. Creating an ASP.NET Web Service in Visual Studio
- Create a web service project.
- Add class library project to the Solution(ref. System.Web.Services).
- Move the service.cs file to class library project. (Please note the Class name here)
- Provide the Strong name Key file in Properties window of Class library project.(Please note the namespace in properties -> Application -> Default Namespace)
- Build the class library project.
- Deploy the dll in Global Assembly Cache.
- Open the service.asmx file
- Replace the existing WebService directive with (Note. In Class, provide class name , namespace and public key token)
<%@ WebService Language="C#" Class="MyServiceClass, MyServiceAssembly,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=8f2dca3c0f2d0131" %> - Run the WebService once by pressing F5 and note the URL. Provide this URL in Disco command in following step.
B. Generating and Modifying Static Discovery and WSDL Files
- Go to Start -> All Programs ->Microsoft visual studio 2005 ->Visual Studio Tools -> Visual Studio 2005 Command Prompt
- Provide your web service URL with Disco.exe here (Example. disco.exe https://localhost:17417/MOSS2007_VS2005Webservice/TejasWebservice.asmx)
- WSDL & DISCO file would be generated.
- Move WSDL & DISCO files from the solution folder to your project folder(we did search for disco file, “service.disco”).
- In WSDL & DISCO file
- Replace
<?xml version="1.0" encoding="utf-8"?>
With
<%@ 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" %>
<% Response.ContentType = "text/xml"; %> - In .DISCO file replace existing contract reference and SOAP address tags
<contractRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request) + "?wsdl"),Response.Output); %>
docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
xmlns="<https://schemas.xmlsoap.org/disco/scl/>" />
<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
xmlns:q1="<https://tempuri.org/>" binding="q1:HelloWorld"
xmlns="<https://schemas.xmlsoap.org/disco/soap/>" />
<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
xmlns:q2="<https://tempuri.org/>" binding="q2:ServiceSoap12" xmlns="https://schemas.xmlsoap.org/disco/soap/>" /> - In the .wsdl file, make the following similar substitution for the SOAP address
that is specified
<soap:address location=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> /> - Rename both files in the respective formats servicedisco.aspx and servicewsdl.aspx so that your service is discoverable through Windows SharePoint Services.
C. Copying the Web Service Files to the Layout and_vti_bin Directories
Copy the Service.asmx, Servicedisco.aspx, Servicewsdl.aspx files to c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS
Copy the Service.asmx, Servicedisco.aspx, Servicewsdl.aspx files to c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI
Now you can go to any of the existing SharePoint site in Internet information Services(inetmgr) and go to _vti_bin folder and select your .asmx file and browse it.