Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The .NET Framework provides extensive support for interoperability through Web services. In C#, using the .NET Framework, Visual Studio, and ASP.NET, creating a Web service is as simple as creating a Web service project and adding an attribute WebMethod to any public method that you want to expose. In addition, the Windows Communication Foundation is a complete platform for creating and consuming Web services as well as many other types of distributed applications.
Java
In Java you can use a Web service package to implement an application such as the Java Web Services Developer Pack or Apache SOAP. For example, in Java you can create a Web service and Apache SOAP using the following steps.
To create a Web service in Java using Apache SOAP
Write a Web service method, as follows:
public class HelloWorld { public String sayHelloWorld() { return "HelloWorld "; } }
Create the Apache SOAP deployment descriptor. This may resemble the descriptor shown:
<dd:service xmlns:dd="http://xml.apache.org/xml-soap/deployment" id="urn:HelloWorld"> <dd:provider type="java" scope="Application" methods="sayHelloWorld"> <dd:java class="HelloWorld" static="false" /> </dd:provider> <dd:faultListener>org.apache.soap.server.DOMFaultListener</dd:faultListener> <dd:mappings /> </dd:service>
Compile class HelloWorld and move it to your Web server's classpath.
Deploy the Web service by using the command line tool.
C#
Creating a Web Service is simpler in C# using .NET Framework classes and the Visual Studio IDE.
To create an ASP.NET Web service in C# using the .NET Framework and Visual Studio
Create a Web service application in Visual Studio. For more information, see C# Application Types for Java Developers. The following is the generated code.
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 () { } [WebMethod] public string HelloWorld() { return "Hello World"; } }
Find the line [WebService(Namespace = "http://tempuri.org/")] and change "http://tempuri.org/" to "http://HowToDevelopWebServicesTest.org/".
To run your C# Web service
Compile and run the service. Type https://localhost/WebSite1/Service.asmx in your Web browser, where localhost is the name of your IIS Web Server and Service is the name of your service, in this case Service.
Output is:
The following operations are supported. For a formal definition, please review the Service Description. HelloWorld
Click on the HelloWorld link to call the HelloWorld method of Service1. The output is:
Click here for a complete list of operations. HelloWorld Test To test the operation using the HTTP POST protocol, click the 'Invoke' button. SOAP 1.1 ... SOAP 1.2 ... HTTP POST ...
Click on the Invoke button to call the HelloWorld method of Service1. The output is:
<?xml version="1.0" encoding="utf-8" ?> <string xmlns="http://HowToDevelopWebServicesTest/">Hello World</string>
For more information about Web services see:
Walkthrough: Creating a Web Service Using Visual Basic or Visual C#
Walkthrough: Creating and Using an ASP.NET Web Service in Visual Web Developer
See Also
Concepts
Other Resources
Change History
Date |
History |
Reason |
---|---|---|
September 2008 |
Removed links to obsolete topics. |
Content bug fix. |