|
||||||||||
|
Creating a Web Service From the Command Line
- In the wwwroot directory, create a directory called MyWebService.
- Open Notepad and enter the following code:
<%@ WebService Language="C#" Class="MyWebService" %>
using System.Web.Services;
public class MyWebService : WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World! Welcome to my web service.";
}
}
- Save this as MyWebService.asmx in the wwwroot\MyWebService directory.- Open the command prompt under Visual Studio .NET Tools in the Start menu. - If you don't have Visual Studio, then you'll need the .NET SDK. - In the command prompt, navigate to the C drive. - Type the following: disco http://localhost/MyWebService/MyWebService.asmx- This creates MyWebService.wsdl in the C drive. - In the command prompt, type the following: wsdl MyWebService.wsdl- This creates MyWebService.cs in the C drive. - In the command prompt, type the following: csc /t:library /out:MyWebService.dll /r:System.Web.Services.dll MyWebService.cs- This creates MyWebService.dll in the C drive. - Open Notepad and enter the following code:
using System;
namespace ConsoleApplication
{
class InvokeWebService
{
[STAThread]
static void Main(string[] Args)
{
MyWebService objMyWebService = new MyWebService();
Console.WriteLine(MyWebService.HelloWorld());
}
}
}
- Save this as InvokeWebService.cs in the C drive.- In the Visual Studio .NET command prompt, type the following: csc /r:MyWebService.dll InvokeWebService.cs- This creates MyWebService.exe in the C drive. - Now all that's left to do is to run the program. Type the following: MyWebService.exe- You should see Hello World! Welcome to my web service.- Now sign my guestbook! |
||||||||||
|
||||||||||