Java Reference
In-Depth Information
Creating a .NET Web Service
Problem
You want to create a web service in ASP.NET.
Solution
In Visual Studio, go to New→Web Site→ASP.NET Web Service. Then enter the implement-
ation code in the generated template.
Discussion
This quick recipe highlights the similarities between a Java EE 5 web service and one written
in .NET using C#. Example 12-10 shows the boilerplate code Visual Studio generates when
you create a new web service.
Example12-10.C# web service template for ASP.NET
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
}
If you substitute in your mind the annotations you use in Java EE 5 with the square brackets
used in C# (or the angle brackets used in VB.NET), it's pretty easy to get around. Much of
the Java EE 5 annotations are based on this way of creating web services in .NET, as this is
Search WWH ::




Custom Search