Creating an XML Web Service with Visual J#

Started by sukishan, Jul 14, 2009, 05:06 PM

Previous topic - Next topic

sukishan

The following walkthrough describes the process for writing a simple XML Web service using Visual J#.

An XML Web service is a way to access server functionality remotely. Using XML Web services, businesses can expose programmatic interfaces to their data or business logic, which in turn can be obtained and manipulated by client and server applications. XML Web services enable the exchange of data in client-server or server-server scenarios, using standards like HTTP and XML messaging to move data across firewalls.

For more information about XML Web services, see Acronym-WebService Sample (Create and Consume an XML Web Service).

Note 
The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.


To create an XML Web service using Visual J#
1. On the File menu, click New, and then click Web Site.

The New Web Site dialog box appears.

2. Click the ASP.NET Web Service icon.

3. In the Language box, select Visual J#.

4. In the Location box, select HTTP if it is not already displayed in the box.

5. In the Location box, type the name and the location of the Web service. Specify VJSharpWebService as the application name.

By default, the project uses your local machine, "http://localhost" as the address of the Web service.

6. Click OK.

7. The Visual Studio template creates a solution for you. The Web service file, Service.asmx, and the corresponding code-behind file, Service.jsl, are created.

8. In Solution Explorer, right-click Service.asmx, and click View Code.

The Code Editor opens the code-behind file Service.jsl.

Notice the following code of the HelloWorld method in the Code Editor:

The resulting method looks like this:


/** @attribute WebMethod() */
public String HelloWorld()
{
   return "Hello World";
}Notice the WebMethod attribute, which indicates that the HelloWorld method is to be exposed as a Web service method.

8. Click Start Without Debugging on the Debug menu to run the project.

The project builds and executes. Internet Explorer opens the URI http://localhost/VJSharpWebService/Service.asmx. This is the test page for all Web services methods of the Web service.

9. Click the HelloWorld hyperlink.

Internet Explorer opens http://localhost/VJSharpWebService/Service.asmx?op=HelloWorld. This is the test page for the HelloWorld Web service method.

10. Click the Invoke button.

Internet Explorer opens a new page that displays the XML code generated by the HelloWorld Web service method, as follows:

<?xml version="1.0" encoding="utf-8" ?>
   <string xmlns="http://tempuri.org/">Hello World</string>
A good beginning makes a good ending