Delphi Write SOAP Server and Client Programs

xiaoxiao2021-03-06  100

Delphi Write SOAP Server and Client Programs

Using the three-layer structure development client, the server software has become the mainstream in the C / S system; the following is some experience in the development system; this article has Delphi7 (Windows) or Kylix3 (Linux9) is an environment Description: 1, write server Program first, look at the establishment of the SOAP server, in the new column in Delphi7, select "WebServices" as shown below, select "SOAP Server Application"

Click "OK" to start selecting the type of Creating Server: Isapi / NSAPI Dynamic Link Library - a .dll file will be generated, you can publish it with IIS; CGI Stand-Alone Executable will generate a CGI program; Note: CGI program is general Compare the memory apache 1.x; apache 2.x can be published in Apache; can be used on different platforms; web app debugger executable is a convenient debugging program that runs with WebAppdbg.exe;

We choose Web App Debugger Executable; mainly for debugging, but it is best to choose IIS as a project (put the compiled program DLL in the publishing directory; select "script and executable" under the IIS home directory configuration option In the browser, enter the corresponding address) or Apache as a carrier of the SOAP server.

Next prompted to create SOAP Module; I have selected "Yes" here; the writing of the server program should pay attention to the process of concurrent access to the client.

Will be generated:

MyTestintf.PAS interface definition file content:

Unit MyTestintf; InterfaceUses InvokeRegistry, Types, Xsbuiltins; Type ImyTest = Interface (IINVOKABLE) ['{FA05E275-DF

6F

-4C

8D-BBF6

-3f

946b187bb3} '] Function login (Name: String; PWD: String): Boolean; stdcall; // Requires method End; ImplementationInitialization Invregistry.registerInterface (TypeInfo (iMytest)); END.

MyTestimpl.PAS interface implementation file content:

unit myTestImpl; interfaceuses InvokeRegistry, Types, XSBuiltIns, myTestIntf; type TmyTest = class (TInvokableClass, ImyTest) public function Login (name: string; pwd: string): boolean; stdcall; end; implementation {TmyTest} function TmyTest.Login (name , PWD: String): Boolean; // Implementation code of the method defined by BEGIN IF ((Name = '1') and (PWD = 'ABC')) THEN Result: = true else result: = false; end; initialization Invregistry.registerInvokableClass (TMYTEST); END.

WEBAPPDBG or IIS boot (1) with WebAppdbg with WebAppdbg, click the Delfault URL to see the published interface; (2) Publish with IIS, enter "http: // localhost / A / Project1.dll "released address; 2. Export the XML document for the SOAP interface

Click "ImyTest" in the browser to save the file "iMytest.xml".

3. Writing of client programs

First, import the XML files exported above to the client program you use in the figure below;

(1) If the server's interface is a method: add the THTTPRIO control in the client, select the file address or URL of the WSDL; the list of the calling interface is as follows: if (httprio1 as Imytest) .login ('1 ',' abc ') Then ShowMessage (' true ') Else ShowMessage (' false ');

(2) If the interface of the server is a data module: put the TSOAPConnection control at the client; set it to the URL; then you can place other data controls (TclientDataSet) to select the above TSOAPConnection; other data The operation is the same as the ordinary data control.

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

New Post(0)