This documentation is archived and is not being maintained.

Web Services Applications (C# vs Java)

Updated: September 2008

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.

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

  1. Write a Web service method, as follows:

    public class HelloWorld 
    {
    
        public String sayHelloWorld()
        {
            return "HelloWorld ";
        }
    }
    
  2. 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>
    
  3. Compile class HelloWorld and move it to your Web server's classpath.

  4. Deploy the Web service by using the command line tool.

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

  1. 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";
        }
    
    }
    
  2. Find the line [WebService(Namespace = "http://tempuri.org/")] and change "http://tempuri.org/" to "http://HowToDevelopWebServicesTest.org/".

To run your C# Web service

  1. Compile and run the service. Type http://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.

  2. Output is:

    The following operations are supported. For a formal definition, please review the Service Description.
    HelloWorld
    
  3. 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
    ...
    
  4. 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:

Date

History

Reason

September 2008

Removed links to obsolete topics.

Content bug fix.

Show: