Web Services Applications (C# vs Java)
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.
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 be similar to the descriptor shown:
<dd:service xmlns:dd="https://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 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 a 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 code generated is illustrated below.
using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; [WebService(Namespace = "https://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 = "https://tempuri.org/")]
and change"https://tempuri.org/"
to"https://tempuri.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="https://HowToDevelopWebServicesTest/">Hello World</string>
For more information on Web services see:
Walkthrough: Creating an XML Web Service Using Visual Basic or Visual C#
Walkthrough: Creating and Using an ASP.NET Web Service in Visual Web Developer
For more information about automated conversion from Java to C#, see What's New in Java Language Conversion Assistant 3.0.