Creating an ASP.NET web services and consuming it with a Win Form  

I am in the very early stages of creating a web site called Sapago.com. I will use it as a place to put sample ASP.NET and ASP.NET web services applications and you will be able to read articles here and download source and view samples on the Sapago site.

So my first example will include a very simple web service which I will consume using a Win Form client. The client will generate a SOAP message containing a request for a method call. The server will invoke the method and serialize the result into a SOAP message which will be returned to the client.

The first step is to create your web service. In my case I already have an ASP.NET web site. So I open the project and add a web service to it. This can be done by right clicking on the solution in the Solution Explorer but in this case I click “Project” on the menu and then select “Add Web Service.”

This creates a simple ASMX file in your project. The ASMX files represent the interfaces to the web service functionality. I called my file Services.asmx as I intend to add other methods to it as I write more samples. Somewhere in the class add a method called ServerTime. It takes no parameters and returns a string.

[WebMethod(Description="Gets the server time and returns it as a string")]
public string ServerTime()
{
string time;
time = System.DateTime.Now.ToLongDateString();
return time;
}

Notice that I have a public method preceded by the WebMethod attribute enclosed in brackets. Using the [WebMethod] tag indicates to the compiler that the following method should be exposed by the web service. This WebMethod attribute includes a number of properties which can be included within parenthesis following the attribute name. This example will work fine without any properties but it I chose to use one and will mention a few others.

In this case I am using the “Description” property. This property allows one to set the description of the particular web method. This is visible on the service splash screen when you call the ASMX file in IE and in the documentation tag of the WSDL file.

 

Home  • MSDN Blog  • Professional Biography  • Personal Biography  • Articles  • Technology  • White Papers  • Downloads  • Contact  • Terms of Use  • Site Map

Channel9  • Spock  • Google  • Programmer's Heaven  •  Variable Markup  • Wuup.de  • Pure  • Net Informations  • San24  • Yahoo Profile  • Excite UK  • Imprese  • NodeWorks  • Travel.com  • Amazon  • Geocities  • T-Links  • SearchBug  • Katalog  • Alexa Search  • Alexa Details  • 15 Seconds  • Blogwise  • Yahoo Profile  • FindArticles  • Julson  • Google Search  • Programmers Heaven author  • Alexa Browse  • MSN  • C9  • Eaton FL  • LinkSpider  • Macopinion  • Italy Link  • DerKeiler  • Programming-X  • CitiBay  • 15S  • Wils Domain  • AdvOL  • Computers Global  • TutorGig  • TGZ  • MV-S  • Deerlake  • mkiwi  • UKFindit • MWTT  • NetInfo • BSC  • WebBozo  • CVCS  • HotLaunch  • Escanaba • Google • FotoPages  • Conk  • InfoBase  • ExciteUK  • Angelfire  • BlogWise  • Canadian Content  • Opera Portal  • oStats  • 411 ASP  •  Interactiva  • Data Mining  • Call Center Forecasting  •  Accounting  • Guitar  • Computers Global  • BIE  • NewsIsFree Alph  • PX Java  • Trexle  • So-Ft  • DMOZ  • Programmer's Heaven Articles  • DotNetKuwait