Create ASMX Service For SharePoint

In this article, we will be seeing the steps to create ASMX Service for SharePoint.

Steps to create ASMX service

Follow the below listed steps to create an ASMX service.

Step 1

Open Visual Studio on your SharePoint Server.


Step 2

Then, create a new empty SharePoint project, provide the name for the project, and select the path.


Step 3

Enter the target web application URL for the deployment and debugging.


Step 4

Then, click on the Finish button to create a new project.


Step 5

Right-click on the project and add the “mapped layout folder” as shown below.


Step 6

Under the layouts folder you can see another subfolder with the project name as shown below,


Step 7

Right-click on the newly created “SampleASMX” folder and select Add >> New Item.


Step 8

When you click on the new item, you will get a popup. Select "General" category from the left navigation, select “Text File.txt”, and provide it a name in the textbox with the .asmx extension, as shown below.


Step 9

Click on the “Add” button to create the .asmx file under the newly created folder.


Step 10

Open the SampleASMX.asmx file and copy and paste the below markup into the file. Then, change the #assembly strong name# with the strong name of your assembly.

Here is the blog post describing how to get the strong name of your assembly by adding an External Tool into Visual Studio.

  1. <%@ WebService Class="SampleASMX.SampleASMX, #assembly strong name#" %>  



After that, we will be changing the Strong Assembly Name. 


Step 11

Right-click the Solution Explorer, add a class file, and provide the name for the class file, as shown below.


Step 12

After you have added the class file, add the “” reference to the project which is available under the framework assemblies.


Step 13

Then, open the .cs file which is newly created, copy and paste the below code to the CS file.

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Web.Services;  
  6. using Microsoft.SharePoint;  
  7. namespace SampleASMX {  
  8.     public class SampleASMX: WebService {  
  9.         [WebMethod]  
  10.         public string GetSiteListCount() {  
  11.             var web = SPContext.Current.Web;  
  12.             return (web.Title + " contains " + web.Lists.Count.ToString() + " lists.");  
  13.         }  
  14.     }  
  15. }  

Step 14

Finally, build and deploy the service by right-clicking on the project in the Solution Explorer and selecting Deploy.


Step 15

After you have deployed the solution successfully, open the browser (i.e IE or Chrome) and browse the below URL.



Step 16

Click the GetSiteListCount link to navigate to a page that will allow you to test your service operation.


Step 17

Click "Invoke" to test your service operation.


Finally, a window should open that has XML contents, as shown below.


You can use this asmx service on your client application.



In this article, we have explored how to create an ASMX service for SharePoint and Deployment steps.

Recommended Ebook

Getting Started with SharePoint Framework Development using TypeScript, PnP JS, and React JS

Download Now!
Similar Articles