C ++ Builder 6 performs SOAP development (2) - Custom type data passed through SOAP

zhaozj2021-02-08  251

C Builder 6 BizSnap / SOAP / WebService (2)

- Pass custom type data via SOAP

This article will make a slightly complex example, implement custom data types passing through SOAP. This example is the function to obtain the data table content at the server's data access control through DBEXPRESS, and then pass it through SOAP to the client again. Server: 1.New | WebServices | Soap Server Application, as shown below, except for the icon in the upper left corner, except for the icon in the upper left corner: WADSOAPDEMO2, 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 the New Interface Wizard: 2. New The interface wizard is as shown below: DATATABLE can generate a SOAP server interface: other instructions on this wizard "C Builder 6 BizSnap / SOAP / Webservice (1) - an example of Hello World!" "(1)"); 3. Put four database controls in the generated WebModule unit: SqlConnection1, SqlDataSet1, DatasetProvider1, ClientDataSet1, its attribute settings are as follows:

SqlConnection1ConnectionName = iblocal; loginprompt = false; params-> values ​​["Database"] = "[...] // eXamplee.gdb"; // above [...] for your interbase installation path SQLDataSet1SQLConnection = SQLConnection1; CommandText = "select FULL_NAME, PHONE_EXT"; DataSetProvider1DataSet = SQLDataSet1; ClientDataSet1ProviderName = DataSetProvider1; WebModule below after completion: 4.SaveAll, Unit1 named: MainWM, Project1 named: Demo2, DataTable not renamed; 5. Add a custom class in the header file of the interface unit (DataTable.h), as follows: Class TdataSetPack: Public Tremotable {

Private:

Int fcount;

Ansistring fxmldata;

PUBLIC:

__fastcall tdataSetPack (TclientDataSet * AclientDataSet)

: Tremotable (),

FCount (aclientDataSet-> RecordCount),

Fxmldata (AclientDataSet-> XMLDATA)

{

}

__published: __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 join 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 iDATABLE

{

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:

// Open ClientDataSet, construct TDataSetPack,

// Turn off ClientDataSet and database connections

// Return the result

TDataSetPack * TDATATABLEIMPL :: getEmployeetable (Void)

{

WebModule2-> ClientDataSet1-> open ();

TDataSetPack * P = new tdataSetPack (webmodule2-> clientdataSet1);

WebModule2-> ClientDataSet1-> Close ();

Webmodule2-> SqlConnection1-> 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. 6. The registration interface and its real class are also the same as "(1), and will not be described again. 7. Compile to generate: 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 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 the above browser can see the correct XML document, select "Next" will generate the result of the import, as shown below: Where we are defined in the server The data type TDataSetPack, interface iDATABLE, and its method getEMPloyEetable, select the interface unit; 4. SaveAll, the iDataTable unit does not change the name, then in the clnmain #include idataable.h; 5. Put a ClientDataSet on the Form, Several controls such as DataSource, DBGRID, Button, Label, have their own property settings as follows:

Default All ClientDataSet1 DataSource1DataSet = ClientDataSet1; DBGrid1DataSource = DataSource1; Button1Caption = "Fetch data"; Label1Caption = "Count: 0"; Form after completion as shown below: Double-click Button1 6. Enter the following procedure: 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 of the server, the number of records will be displayed in Label1, as shown below; this is just an example of a simple database access, only from the server to retrieve the data set, The MIDAS / DASNAP and SOAP / WebService have been combined in C Builder 6, which can be implemented through SOAP / WebService, which will be introduced in future articles. [Mental Studio] Raptor APR.30-02

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

New Post(0)