ASP.NET and Web Services Part 2 - Web Service Code Sample
(Page 2 of 8 )
Listing 6 IFCEBrokerageFirm web service code
using System
;
using System.Web;
using System.Web.Services;
namespace IFCEBrokerage
{
public class SecuritiesExchange :
System.Web.Services.WebService
{
[WebMethod]
public
double StockQuote(string symbol)
{
double
quotePrice=0;
switch(symbol)
{
case "JANS":
quotePrice = 29.95;
break;
case
"MSFT":
quotePrice =
49.97;
break;
case
"ORCL":
quotePrice =
37.72;
break;
}
return
quotePrice;
}
}
}
Several IFCEBrokerageFirm items require clarification. An excellent place to begin learning about them is in web service namespaces.
Table 1 displays them with comments.
These namespaces enable developers to create XML web services using ASP.NET and XML web service clients. XML web services represent applications that enhance the ability to exchange messages in a loosely coupled environment using protocols such as HTTP, XML, XSD, SOAP, andWSDL. They facilitate constructing modular
applications in a heterogeneous environment that promotes interoperability between applications, smart client devices, and implementations.
NOTE
The WebMethodAttribute class must be applied to any method where a developer wants to expose it programmatically.
| Class | Description |
| WebMethodAttribute | Adding this attribute to a method when defining a web service created in ASP.NET makes the method callable from remote web clients. |
| Web Service | This class defines the optional class for XML web srvices, thereby providing access to common ASP.NET objects, for example, applications and sessions state. |
| WebServiceAttribute | This class is used to append additional information to an XML web service, such as a string explaining its functionality. |
| WebServiceBindingAttribute | Declares binding for one or more XML web service methods implemented within the class that is implementing the web service. |
Remember: This is part one of chapter 7 .NET & J2EE Interoperability, by Dwight Peltzer (McGraw-Hill/Osborne, ISBN 0-07-223054-1, 2004). If you like what you see, feel free to click on the following link to get your own copy! Buy this book now.
|
Next: The .asmx File >>
More ASP.NET Articles
More By McGraw-Hill/Osborne