We need to do the following five steps
1) Create the web service.
2) Run disco.exe to get static disco and wsdl file for the web service.
3) Put asmx, disco and wsdl file to ISAPI folder.
4) Rename disco and wsdl file to aspx. Replace static url’s in them.
5) Add an entry to spdisco.aspx
Let’s proceed
· Create a new ASP.NET web service project.
· Rename Service.asmx to HWService.asmx.
· Right click it – select View Mark Up.
· And put the following mark up. Here we will be creating the web service with inline code.
<%@ WebService Language=”C#” Class=”MyInlineService.HelloWorldService” %>
using System.Web.Services;
namespace MyInlineService
{
public class HelloWorldService: WebService
{
[WebMethod]
public string HelloWorld()
{
return “Hello World”;
}
}
}
· Now Run Disco.exe for our HWService.asmx to create static disco and wsdl file.
· Open visual studio command prompt and run the following command
disco http://localhost:1814/HelloWorldSPService/HWService.asmx
· This will create HWService.wsdl and HWService.disco files at the current directory.
· Now copy all the three files HWService.asmx,HWService.wsdl and HWService.disco to ISAPI folder.
· Rename HWService.disco to HWServicedisco.aspx and HWService.wsdl to HWServicewsdl.aspx.
· Now we will open these new renamed wsdl and disco files to make the following modifications.
Open HWServicewsdl.aspx.
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”; %>
And
<soap:address location=”http://localhost:1814/HelloWorldSPService/HWService.asmx” />
To
<soap:address location=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> />
Open HWServicedisco.aspx
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”; %>
And
with
<contractRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request) + “?wsdl”),Response.Output); %>
docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
· Adding it’s entry in spdisco.aspx
Open the spdisco.aspx and add the following entry
<contractRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + “/_vti_bin/HWService.asmx?wsdl”), Response.Output); %>
docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + “/_vti_bin/HWService.asmx”), Response.Output); %>
<discoveryRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + “/_vti_bin/HWService.asmx?disco”),Response.Output); %>
Now your web service should be availabe to be used within sharepoint context
http://servername:port/_vti_bin/HWService.asmx.
That’s it!!
Posted in SharePoint Tagged: SharePoint
*This post is locked for comments