C ++ Builder 6 BizSnapSOAPWebService (2) - Custom Type Data (Changed) via SOAP

zhaozj2021-02-08  282

Explanation: This article has been changed, and some problems have been corrected because the original text cannot be modified. Not long ago, I received several friends to send Mail to explain that they encountered when they were developed in this article: AV errors occur when writing this article as an example of this article in the ISAPI. According to the improved this example, this article is modified, please note the comparison part of the text. --2002-8-17

This article will make a slightly complex example, implement custom data types passing through SOAP. This example is the function to obtain data table content at the server through the ADO data access control, and then pass it through SOAP to the client again.

Server: 1.New | WebServices | Soap Server Application, as shown below, except for icons in the upper left corner than Delphi 6 Update 2, except for icons in the upper left corner:

Select the web app debugger executeable type, coclass name is: WadsoapDemo2, as shown below:

After confirming, you will automatically prompt whether you want to create a new interface, you can open a new interface forward, if you want to add an interface, you can select SOAP Server Interface in New | WebServices, you can also open a new interface Wizard:

2. New Interface Wizard is as shown below, enter the interface name: DATATABLE can generate a SOAP server interface:

Other instructions on this wizard see "C Builder 6 BizSnap / SOAP / Webservice (1) - An example of Hello World! (1)"); 3. (Note: This part of the original is wrong, Now after modification) new DataModule, add four database controls: Adoconnection1, Adodataset1, DataSetProvider1, ClientDataSet1, which are set as follows:

ADOConnection1ConnectionString = "Provider = SQLOLEDB.1; Persist Security Info = False; User ID = sa; Initial Catalog = Northwind; Data Source = raptor / neutrino"; LoginPrompt = false; ADODataSet1Connection = ADOConnection1; CommandText = "select FirstName, LastName from Employees "; DataSetProvider1DataSet = adodataset1; clientDataSet1ProviderName = DataSetProvider1;

DataModule after completion, as shown below:

(About this part of the supplementary description): The original DBEXPRESS will appear "Unable Load DBEXPINT.DLL" when used for ISAPI, so use the ADO. In addition, if there is no AdoClientDataSet control, if BDE / DBEXPRESS / IBEXPRESS is only two controls. To put the data control in a separate DATAMODULE, it is not possible to see the reason for "Web Application", talk about the difference between WAD / CGI / ISAPI ", this example is for reference only, it is recommended to operate in database operations In applications, it is best to use SOAP Server Data Module (such as "C Builder 6 BizSnap (3) - DataNAP Database Application"). 4. SaveAll, unit1 named: mainwm, unit2 named Demo2DM, project1 named: demo2, DataTable does not change the name; 5. Add a custom class in the header file of the interface unit - TDataSetPack, as follows : Class TdataSetPack: Public Tremotable {

Private:

Int fcount;

Ansistring fxmldata;

PUBLIC:

__fastcall tdataSetPack (TCUSTOMCLIENTDATASET * ACLIENTDATASET)

: Tremotable (),

FCount (aclientDataSet-> RecordCount),

Fxmldata (AclientDataSet-> XMLDATA)

{

}

__publish:

__property int count = {read = fcount};

__property ansistring xmldata = {read = fxmldata};

}

Custom SOAP data type must be derived from the Tremotable class, this is the same as Delphi. Where the ClientDataSet's XMLDATA attribute is new from Delphi 6. In fact, XMLDATA has already included recorded information, and Count attributes are not required, here in order to demonstrate the use of custom SOAP data types, this property is added. Note: To join: #include 5. Define and implement the getEMPloyEetable function, the method is the same as "(1)", below is the DATATABLE.H and unit files (DATATABLE.CPP) interface / class definitions and methods of our joining and its implementation:

// DataTable.h

__interface interface_UUID ("{CF057C28-4130-4508-9F24-0BBD1C2CA5F0}")

IDATABLE: Public Iinvokable

{

PUBLIC:

Virtual TdataSetPack * geteMPloyEetable (void) = 0; // New method

}

Typedef DelphiInterface

_di_idataable;

// DataTable.cpp

Class TdataTableImpl: Public TinvokableClass, Public iDataTable {

PUBLIC:

TDataSetPack * getEmployeetable (void); // Add method

/ * IUnknown * /

HRESULT stdmethodcalltype queryinterface (const guid & iid, void ** obj)

{RETURN GetInterface (IID, OBJ)? S_OK: E_NOINTERFACE;}

Ulong stdmethodcalltype addref () {returnTurn TinterFaceDObject :: _ addref ();}

Ulong stdmethodcalltype release () {return TinterFaceDObject :: _ release ();}

/ * ENSURES THAT THE CLASS IS NOT ABSTRACT * /

Void checkvalid () {delete new tdataableImpl ();

}

// Realization of new methods:

/ / If it is a CGI / ISAPI application, you need to create a new DATAMODULE1, and the corresponding modification will be described later.

// Open ClientDataSet, construct TDataSetPack,

// Turn off ClientDataSet and database connections

// Return the result

TDataSetPack * TDATATABLEIMPL :: getEmployeetable (Void)

{

// If it is CGI / ISAPI, you want this sentence

// Application-> Createform (__ classid (tdataModule1), & dataModule1);

DataModule1-> ClientDataSet1-> open ();

TDataSetPack * P = new tdataSetPack (DATAModule1-> ClientDataSet1);

DataModule1-> ClientDataSet1-> Close ();

DataModule1-> Adoconnection1-> Close ();

Return P;

}

In addition to the implementation of the method, the other portions are substantially the same as "(1)". The implementation function of this method is just as indicated in the program, and returns the data set and converted to our defined data type. (About this part of the supplementary instructions): Note If the CGI / ISAPI application, the DATAMODULE1 is dynamically created (why, as described in the implementation process of "web application - talk about WAD / CGI / ISAPI"), Corresponding to the project | source (ie, Demo2cgi.cpp / demo2isapi.cpp) will automatically create a statement to automatically create a statement.

Application-> Createform (__ classid (twebmodule1), & webmodule1);

// Don't this sentence if it is a CGI / ISAPI application

// Application-> Createform (__ classid (tdataModule1), & dataModule1);

Application-> Run ();

6. The registration interface and its real class are also the same as "(1), and will not be described again. 7. Compile: demo2.exe;

First run Demo2.exe, start the Web App Debugger after completing the registered work. Open the browser, enter the URL as: http: // localhost: 1024 / demo2.wadsoapdemo2 to see a standard SOAP application description page, click to enter the appropriate link to see the related WSDL, you can see us Defined data type description, as shown in the following WSDL segment:

Client Program: 1.New | Application Create a new general VCL application; 2.saveAll, unit1 named clnmain, project1 named client; 3.New | Web Services | Web Services IMPORTER: Enter: http in the URL in the picture below: HTTP : // localhost: 1024 / demo2.wadsoapdemo2 / wsdl / iDATABLE,

If you can see the correct XML document with a browser above, select "Next" will result in the result of the import, as shown below:

One of them has the data type TDataSetPack, interface iDATABLE, and its method to generate the interface unit, and the selection is completed; 4. SaveAll, the iDataTable unit does not change the name, and then in the clnmain #include iDataTable.h; 5. A few controls such as ClientDataSet, DataSource, DBGRID, Button, Label, etc., and each of the following tables:

ClientDataSet1 all default Datasource1DataSet = ClientDataSet1; dbgrid1datasource = DataSource1; button1caption = "fetch data"; label1caption = "count: 0";

After completing FORM as shown below:

6. Double-click Button1 Enter the following program:

Void __fastcall tform2 :: Button1click (TOBJECT * SENDER)

{

TDataSetPack * p = getidataable () -> getEMPloyEetable ();

Label1-> Caption = Ansistring ("count:") INTOSTR (P-> Count);

ClientDataSet1-> xmldata = p-> xmldata;}

7. Compile operation, press button1, DBGRID1 will display the data set content returned by the server, and the number of records will be displayed in Label1, as shown in the following figure (description, this figure is still the original data when INTERBASE);

This is just an example of a simple database access, which can only be retrieved from the server, and the MIDAS / DASNAP and SOAP / WebService can be combined in C Builder 6, which can be very powerful database operation capabilities through SOAP / WebService. Introduced in future articles.

[Mental Studio] Raptor APR.30-02

转载请注明原文地址:https://www.9cbs.com/read-2642.html

New Post(0)