Microsoft Visual C++ .NET Professional Projects - Premier Press
.pdf
722 Project 7 CREATING WEB SERVICES
//Class1 Is the class In the Web service
Class1 *Ws=new Class1();
lst=Ws->getArtList();
Once a reference to the array returned by the Web service is obtained, you can access each ArtData object as follows:
lst[0]->ProdID //The prodID of the first art object
The following is the complete code for the constructor to access the details of all the art objects and display them in a list view:
MainForm::MainForm()
{
ArtData *lst[]; int i=0;
Class1 *Ws=new Class1(); lst=Ws->getArtList();
lv=new ListView(); lv->Dock=DockStyle::Top; lv->View=View::Details;
lv->Columns->Add(“Product ID”,45,HorizontalAlignment::Left); lv->Columns->Add(“Product Type”,160,HorizontalAlignment::Left ); lv->Columns->Add(“Product Name”,160,HorizontalAlignment::Left ); lv->Columns->Add(“Product Price”,100,HorizontalAlignment::Left );
for(i=0;i<lst->Count;i++)
{
lvi=lv->Items->Add(lst[i]->ProdID); lvi->SubItems->Add(lst[i]->ProdType); lvi->SubItems->Add(lst[i]->ProdName); lvi->SubItems->Add(lst[i]->ProdPrice);
}
this->Controls->Add(lv);
}
CREATING A WEB SERVICE USING MANAGED EXTENSIONS Chapter 23 723
Summary
In this chapter, you created a simple Web service using Managed Extensions for C++. You saw how Visual C++ .NET encapsulates most of the difficult details of creating a Web service, thereby increasing developer productivity. You have also learned how to access the Web service from a Managed C++ client.
This page intentionally left blank
AWeb service is a way for a Web site to expose programmatic functionality. Web services accept input in the form of messages and reply through messages. These messages can be sent and received using HTTP-POST, HTTP-
GET, or SOAP. Visual C++.NET makes it very simple to create a Web service.
In the last chapter, you created a Web service using Managed Extensions for C++. However, that Web service was created on the .NET platform. What about a Windows installation that is not .NET based? Well, you can create Web services for such platforms by using the ATL Server library.
In Chapters 20 and 21, you worked with ATL Server to create a Web application. Using the same ATL Server library, you will now create a Web service.
However, creating a Web service using ATL Server is not as simple and clean as doing it in any of the other .NET languages, such as Visual Basic and C#. Then, why would anyone want to use the ATL Server library? Here are some of the reasons why you would prefer the ATL Server:
ATL Server Web services offer very high performance.
You have existing skills and competency in using ATL-based libraries. (This is directed to the chores of VC++ programmers out there!)
So, get set to try out ATL Server programming to create Web services. As a starter, I present a scenario wherein you can implement the ATL Server Web services. Later, I will guide you through the steps to be performed to create the ATL Server Web service.
Exchange Rate Web Service
NJ Finances (NJF) is a reputed financial services company based in New York. It has a Web site that, among other things, offers public articles on finance, descriptions of the company’s mutual funds, and a stock ticker.
NJ Finances now is adding a few more features to its Web site:
Free access to articles on investing and financial management written by the company’s financial consultants.
CREATING A WEB SERVICE USING ATL SERVER |
Chapter 24 |
727 |
|
|
|
|
|
A complete tutorial on money trading and investments in foreign countries.
Business news from various countries sourced and syndicated from local newspapers.
A Web service that gives the rate of exchange for currencies of different countries updated on a daily basis.
The company’s MIS and software division are involved in upgrading the site.
Project Life Cycle
In the project-initiation phase, the project plan was prepared and the development team for the project was also identified. The development team further prepared a comprehensive list of tasks involved in the execution and the deployment phases of the project’s life cycle.
Moving further, you will look at the tasks performed by the development team in the following stages of the project-execution phase:
Requirements analysis
Design
Construction
Testing
What follows is a description of the tasks performed by the development team in each of these stages.
Requirements Analysis
During the requirement analysis phase, the development team at NJF identified the need to use a Web Service application and came up with the following requirements:
The Web service should run on a server that does not have the .NET platform installed.
The Web service should expose methods that return the current exchange rate and the denomination for a given country.
CREATING A WEB SERVICE USING ATL SERVER |
Chapter 24 |
729 |
||||
Table 24-1 Structure of the IMFRates Table |
|
|
|
|
||
|
|
|
|
|||
|
|
|
|
|
|
|
Field |
Data type |
Size |
|
|
|
|
|
|
|
|
|
|
|
Country |
Varchar |
20 |
|
|
|
|
Denomination |
Varchar |
10 |
|
|
|
|
ExRate |
Varchar |
10 |
|
|
|
|
|
|
|
|
|
|
|
Once the table is ready, you need to populate it with some data. The International Monetary Fund publishes representative exchange rates daily at its site. To pick up values from there:
1.Go to the site www.imf.org.
2.Navigate to the site map page.
3.On the site map page, click on the link representative rates for selected currencies. On this page, you find the exchange rates for most of the countries.
You can populate the database table from data on this page.
Besides this table, you also need to create two stored procedures:
The getDenom stored procedure accepts the name of the country as a parameter and returns the corresponding currency denomination.
The getRate stored procedure accepts the name of a country and returns the exchange rate.
Next, you will create these two stored procedures.
The code for creating the getDenom stored procedure is as follows:
CREATE PROCEDURE getDenom
@country varchar(20)
AS
select Denomination from rates where country=@country
GO
The code for creating the getRate stored procedure is as follows:
CREATE PROCEDURE getRate
@country varchar(20)
AS
select ExRate from rates where country=@country
GO
