Creating a custom Hello World web service in SharePoint


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&#8221; />

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

<contractRef ref=”http://localhost:1814/HelloWorldSPService/HWService.asmx?wsdl&#8221; docRef=”http://localhost:1814/HelloWorldSPService/HWService.asmx&#8221; xmlns=”http://schemas.xmlsoap.org/disco/scl/&#8221; />

<soap address=”http://localhost:1814/HelloWorldSPService/HWService.asmx&#8221; xmlns:q1=”http://tempuri.org/&#8221; binding=”q1:HelloWorldServiceSoap” xmlns=”http://schemas.xmlsoap.org/disco/soap/&#8221; />

<soap address=”http://localhost:1814/HelloWorldSPService/HWService.asmx&#8221; xmlns:q2=”http://tempuri.org/&#8221; binding=”q2:HelloWorldServiceSoap12″ xmlns=”http://schemas.xmlsoap.org/disco/soap/&#8221; />

with

<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/&#8221; />

<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>

xmlns:q1=”http://tempuri.org/&#8221; binding=”q1:HelloWorld” xmlns=”http://schemas.xmlsoap.org/disco/soap/&#8221; />

<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>

xmlns:q2=”http://tempuri.org/&#8221; binding=”q2:ServiceSoap12″ xmlns=”http://schemas.xmlsoap.org/disco/soap/&#8221; />

· 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); %>

xmlns=” http://schemas.xmlsoap.org/disco/scl/ />

<discoveryRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + “/_vti_bin/HWService.asmx?disco”),Response.Output); %>

xmlns=”http://schemas.xmlsoap.org/disco/&#8221; />

Now your web service should be availabe to be used within sharepoint context

http://servername:port/_vti_bin/HWService.asmx.

That’s it!!


Discover more from Nishant Rana's Weblog

Subscribe to get the latest posts sent to your email.

Unknown's avatar

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

5 thoughts on “Creating a custom Hello World web service in SharePoint”

  1. Be careful if you are reading this page in Firefox. Some of the text seems to get clipped. The text is there, you just can’t see it. Copy/paste may or may not work. View source will work, but IE seems to be your best bet on this page.

    Like

Leave a reply to bill Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Nishant Rana's Weblog

Subscribe now to keep reading and get access to the full archive.

Continue reading

Power Platform Puzzles

D365 CRM, Power Platform Tips &Tricks

Power Spark

Power Spark By Shrangarika

Van Carl Nguyen

Exploration of Power Platform

My Trial

It is my experience timeline.

Power⚡Thomas

Sharing my knowledge and experience about the Microsoft Power Platform.

Arpit Power Guide

a guide to powering up community

Welcome to the Blog of Paul Andrew

Sponsored by Cloud Formations Ltd

Deriving Dynamics 365

Deriving Solutions and features on Power Platform/Dynamics 365

The CRM Ninja

Thoughts & musings from a Microsoft Business Applications Ninja!

D CRM Explorer

Learn about Microsoft Dynamics CRM Power Platform customization and implementation and other cool stuffs

Stroke // Jonas Rapp

I know pre-stroke. I will improve who I was.

Power Melange

Power Melange By Shalinee

Clavin's Blog - PPUG.ORG

AI - Power Automate - Power Apps - SharePoint Online - Azure - Nintex - K2 - Artificial Intelligence

Sat Sangha Salon

An Inquiry in Being

The Indoencers

The Influencers & Influences of Indian Music

Monika Halan's blog

Hand's-free money management

D365 Demystified

A closer look at Microsoft Dynamics 365.

Microsoft Mate (msftmate) - Andrew Rogers

Experienced consultant primarily focused on Microsoft Dynamics 365 and the Power Platform

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions

MG

Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue

The Professional Paraphraser

Subwoofer 101

Bass defines your home theater

SQLTwins by Nakul Vachhrajani

SQL Server tips and experiences dedicated to my twin daughters.

Everything D365

Discovering Azure DevOps and D365 Business Applications

Tech Wizard

Lets do IT Spells

XRM Tricks (Power Platform & Dynamics CRM )

Power Platform & Dynamics CRM

CRM TIPS BY PRM

Mail to crmtipsbyprm@gmail.com for queries and suggestions

nijos.dev

Giving back to the community what I have learned

Power Platform Learning

Your Go-To Resource for Power Apps, Power Automate & More

xrm CRM Dynamics

Dynamics CRM Technical & Functional Info

Dynamics 365 Blogs - Explained in unique way

Sometimes you need to look at things from different perspective.