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.

Visual Studio

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.

Finish button

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

Layout folder

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 the "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.

Text File.txt

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.

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


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

Strong Assembly

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

Solution Explorer

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

 Class file

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Services;
using Microsoft.SharePoint;

namespace SampleASMX 
    public class SampleASMX : WebService 
        public string GetSiteListCount() 
            var web = SPContext.Current.Web;
            return (web.Title + " contains " + web.Lists.Count.ToString() + " lists.");

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.