Web services can be developed in any programming language supported by .NET. Out-of-the-box it includes Visual C#, Visual Basic .NET, Visual J#, and Managed C++. In the following sections, you'll take a look at how Web services can be developed in other .NET supported programming languages. Using Visual Basic .NET<%@ WebService Language="VB" Class="hks.HelloService"%> Imports System.Web.Services Namespace hks <WebService(Namespace:="http://www.hitehseth.com/WebServices")> _ Public Class HelloService <WebMethod(Description:="Simple Hello Method")> _ Public Function sayHello() as String Return "Returned from a Visual Basic.NET Web Service" End Function End Class End Namespace Using Visual J#<%@ Webservice class="hks.HelloService" language="VJ#"%> package hks; import System.Web.Services.*; /** @attribute WebService(Namespace="http://www.hiteshseth.com/WebServices") */ public class HelloService { /** @attribute WebMethod(Description="Simple Hello Method") */ public String sayHello() { return "Returned from a Visual J# Web Service"; } } Using Managed C++Because inline managed C++ is not supported by ASP.NET, developing a managed C++ based Web service involves a couple more steps than developing it in C#, for instance. First create an .asmx file (HelloCPPService.asmx) that references an appropriate .NET class. <%@ WebService Class="hks.HelloService"%> Next, you need to develop and implement the .NET class "hks.HelloService." You first create a header file (stdfax.h) to state that you are using some of the .NET Framework class libraries to develop the Web service. #pragma once #using <mscorlib.dll> #using <System.dll> #using <System.Web.dll> #using <System.EnterpriseServices.dll> Then you need to implement the .NET Web service itself, using managed C++. As you can see from the following code, developing a managed C++ Web service is really like developing any other .NET component, but with the Web services- related tags in place. #include "stdafx.h" using namespace System; using namespace System::Web; using namespace System::Web::Services; namespace hks { [WebService(Namespace="http://www.hiteshseth.com/WebServices")] public __gc class HelloService { public: [WebMethod(Description="Simple Hello Service")] String __gc* HelloWorld() { return S"Returned from Mangaed C++ Web Service"; }; }; } Now using the command-line based .NET Framework managed C++ compiler (with the /CLR option), compile the managed C++ program into a .NET assembly (DLL). Next, place the generated DLL into the bin directory of the Web application (where the .asmx file is located) and invoke the Web services URL ( http://localhost/HelloCPPService.asmx ) in a browser. You should see the familiar Web services test page displayed. |