Java Reference
In-Depth Information
basically the API Microsoft has provided since 2002. Instead of calling them “annotations” as
you do in Java, in .NET the meta-code above classes and methods are called “attributes.”
You can see that the code itself indicates that it will conform to the Basic Profile version 1.1.
Let's add a few other attributes to see how you can control the web service with a few para-
meters. Example 12-11 is your simple update of the boilerplate file.
Example12-11.Greeting web service, Service.asmx
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(
Namespace = "http://soacookbook.com/dotnet",
Name="GreetingService",
Description="Returns greetings.")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1,
EmitConformanceClaims=true)]
public class Service : System.Web.Services.WebService
{
public Service () { }
[WebMethod(MessageName="HelloMsg",
Description="Returns a nice greeting.",
CacheDuration=100)]
public string niceGreeting(string name) {
return "Hello " + name + " from " +
Server.MachineName;
}
}
We've modified the attributes a bit, and added an implementation for the operation.
Web services in .NET have a .asmxfile extension. This file is called Service.asmx, so you can
access it through your browser at http://localhost:3416/WebSite1/Service.asmx after
publishing the site to your local IIS.
If you access the service page directly, IIS returns a service home page, shown in Figure 12-2 ,
similar to what you would see if you deployed a web service to Apache Axis. It gives you a
link directly to the WSDL via the “Service Description” link (or you can just append ?WSDL to
the URL as usual). This home page also prints the description you entered in the WebMethod
attribute.
Search WWH ::




Custom Search