Step by step to implement Web Service with Delphi6

zhaozj2021-02-08  262

This article describes how to develop a Web Service program with Delphi6 and put the service programs on the IIS Web server to all customer programs.

A writing service program

Step 1: File -----> New -----> Other ------> WebServices -----> SOAP Server Application

Select ISAPI / NSAPI Dynamic Link Library and then determine. Generate a frame. Most of the original code behind you need to add yourself

Step 2: Define an interface unit. By an empty cell file first, then enable the basic interface (IINVOKABLE) and the method that the client program can be called in this unit, the original code is as follows:

Unit Unit1; InterfaceUses InvokeRegistry; // Basic Structure and Method Definition of Basic Structure and Method All in this unit, must reference a TypeiWebtest = Interface (Iinvokable) // Customized structure, inherit from Iinvokable ['{A436B0D2-D490-4C80-820A -355D979E8704} '] // A guidFunction getText (): wideString; stdcall; // is customized by Ctrl Shift G; a method of customizing the customer can call; importation

Initialization // Initialization INVREGISTRY.REGISTERFACE (TypeInfo (iWebTest)); // The interface end is registered by this method.

Step 3: Implement the interfaces and methods defined in the second step. Create an empty unit file first, then define the implementation of the custom interface (iWebtest). The original code is as follows:

Unit unit2;

interfaceuses InvokeRegistry, Unit1; // reference to the interface unit typeTWebTest custom = class (TInvokableClass, IWebTest) // define the implementation class, which must be derived from TInvokableClass, and customizable interfaces protectedfunction gettext (): widestring; stdcall; // Declaring the method defined in custom interfaces; Implementation

{Test} Procedure CreateWebTest (Out Obj: TOBJECT); // This process is to create a class instance, you must manually add beginobj: = twebtest.create; // creation class instance end; function TWEBTEST.GETTEXT: WIDESTRING; / / Implement custom customization Method BeginResult: = 'Success'; End; Initialization // Initialization Invregistry.registerInvokableClass (TWEBTEST, CREATEBTEST); // Register Custom Class END.

Step 4: Compile the entire application, which generates a * .dll program, copy this program to the cgi-bin directory of IIS (or other executable directories, to select according to your own directory), then Access to WSDL: http: //192.168.1.222/cgi-bin/*.dll/wsdl is accessed by links to the WSDL file encoded in XML mode, which is the file required by the client program call. Where * .dll is the name of your own application. 192.168.1.222 is your web server address. CGI-bin is a directory name that can perform CGI programs for your web server.

Second write client:

Step 1: Create a new Application. Step 2: File -----> New -----> Other ------> WebServices -----> SOAP SERVICES IMPORTER

Then fill in the WSDL or XML Schema Location: http: //192.168.1.222/cgi-bin/*.dll/wsdl/iWebTest, then determine a new interface definition unit.

Step 2: Place a button and an HTTPRIO component on the master form (on the webservices page) and reference the second unit (ie, the unit automatically generated by SOAP Services Importer)

Fill in http://192.168.1.222/cgi-bin/*.dll/wsdl/iWebtest on the WSDLOCATION on the attribute page of HTTPRIO; then select the appropriate data on the port and service on the HTTPRIO property page.

Step 3: Write a customer call program, the original code is as follows:

Procedure tForm1.button1click (sender: TOBJECT); VARTESTOBJ: IWEBTEST; / / Define Object BegintestObj: = httprio1 as IWebtest; // Create Object ShowMessage (Testobj.getText); // Call method END; //

The above is a simple example, interested, can be discussed with me. The above example also uses Java customer calls pass. My mailbox is coala@21cn.com

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

New Post(0)