ASP.NET Web Services (ASMX) Tutorial with Examples
π₯ Beginner to Advanced Guide with Examples, Diagrams & Code
ASP.NET Web Services Tutorial: In modern web development, applications often need to communicate with external systems such as payment gateways, weather APIs, or news feeds. Instead of building everything from scratch, developers can reuse existing services. ASP.NET Web Services (ASMX) provide a simple way to expose and consume business logic over the internet using standard protocols like HTTP and XML.
π What Are ASP.NET Web Services?
Web Services are software components that allow applications to communicate over a network. They enable interoperability between different platforms and programming languages.
- Platform independent
- Language independent
- Uses XML-based communication
- Accessible via HTTP
π ASP.NET Web Services Architecture Diagram

The diagram above shows how a client sends a request to a web service, which processes it and returns a response.
βοΈ How ASP.NET Web Services Work

- Client sends request (SOAP/XML)
- Server processes request
- Response returned in XML format
π οΈ Creating an ASP.NET Web Services Application
Step 1: Create Project
Open Visual Studio β Create ASP.NET Web Service Application β Select .NET Framework.
Step 2: Sample Code
[WebMethod]
public int AddNumbers(int a, int b)
{
return a + b;
}
π·οΈ Important Attributes
- WebService β Defines service metadata
- WebMethod β Exposes method
- WebServiceBinding β Protocol standard
- ScriptService β Enables AJAX calls
β οΈ Method Overloading Limitation
Web Services do not support method overloading directly.
[WebMethod(MessageName = "AddFloat")]
public float AddNumbers(float a, float b)
{
return a + b;
}
π§ͺ Testing Web Service
Run the project and open:
http://localhost/MyService.asmx
You will see available methods and WSDL document.
π WSDL in ASP.NET Web Services Explained

WSDL is an XML-based document that describes the web service methods, parameters, and communication format.
π Hosting on IIS
- Open IIS Manager
- Add Application
- Set physical path
- Configure default document
π Consuming Web Service in C#
var client = new MyServiceSoapClient(); int result = client.AddNumbers(10, 20);
π Calling Web Service Using AJAX
$.ajax({
type: "POST",
url: "MyService.asmx/AddNumbers",
data: JSON.stringify({ a: 5, b: 10 }),
contentType: "application/json",
success: function(response) {
console.log(response.d);
}
});
π‘ SOAP XML Example
<soap:Envelope>
<soap:Body>
<AddNumbers>
<a>5</a>
<b>10</b>
</AddNumbers>
</soap:Body>
</soap:Envelope>
β Limitations
- Heavy XML format
- Slower than REST APIs
- Outdated technology
π Modern Alternatives
- ASP.NET Web API
- REST APIs
- gRPC
This ASP.NET Web Services Tutorial helps beginners understand how SOAP-based services work in real-world applications.
π Conclusion
ASP.NET Web Services (ASMX) are a foundational technology for distributed systems. While modern APIs have replaced them in many scenarios, they are still useful for legacy systems and understanding service-based architecture.
π Learn more: ASP.NET Core Tutorial
π Official Microsoft Docs:
ASP.NET Web Services Documentation
π Tags
asp.net web services, asmx tutorial, soap vs rest, wsdl explained, web service example c#