How To: Steps to create web services in MOSS 2007


I followed the article http://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

  1. Create a web service project.
  2. Add class library project to the Solution(ref. System.Web.Services).
  3. Move the service.cs file to class library project. (Please note the Class name here)
  4. Provide the Strong name Key file in Properties window of Class library project.(Please note the namespace in properties -> Application -> Default Namespace)
  5. Build the class library project.
  6. Deploy the dll in Global Assembly Cache.
  7. Open the service.asmx file
  8. 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" %>
  9. 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

  1. Go to Start -> All Programs ->Microsoft visual studio 2005 ->Visual Studio Tools -> Visual Studio 2005 Command Prompt
  2. Provide your web service URL with Disco.exe here (Example. disco.exe http://localhost:17417/MOSS2007_VS2005Webservice/TejasWebservice.asmx)
  3. WSDL & DISCO file would be generated.
  4. Move WSDL & DISCO files from the solution folder to your project folder(we did search for disco file, “service.disco”).
  5. In WSDL & DISCO file
  6. 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"; %>
  7. 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="<http://schemas.xmlsoap.org/disco/scl/>" />
    <soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
    xmlns:q1="<http://tempuri.org/>" binding="q1:HelloWorld"
    xmlns="<http://schemas.xmlsoap.org/disco/soap/>" />
    <soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
    xmlns:q2="<http://tempuri.org/>" binding="q2:ServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/>" />
  8. 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); %> />
  9. 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

  1. Copy the Service.asmx, Servicedisco.aspx, Servicewsdl.aspx files to c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS
  2. 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.

Comments (0)

Skip to main content