Webservice developed and called by Delphi
When using delphi to write webservice, the first problem is how to write it. how to write it? After checking online, I still heard a lot of content. Of course, by comparing multiple sources of data, I learned that through file -- new ---- other ---- webservice, I can establish and test webservice, but I didn't have this option in delphi, so I was very confused. I asked the "Daniel" programmer to know that it was because my vcl package was removed, therefore, the corresponding package is found in the bin directory of the Installation File of delphi. After the installation is complete, the webservice is compiled and tested.
The following describes how to compile an ISAPI-type WebService for IIS.
1. New | Other | WebServices | SOAP Server Application | create a Web App Debugger-type WebService first, because this type of WebService is easy to debug. When we debug it, this type is converted to the ISAPI type when you prepare for release.
2. After selecting the Web App Debugger, enter a ClassName. Here we enter "Test"
3. Then, Delphi will ask you if you want to establish an interface unit. Select Yes and enter the interface name. Let's enter Main, delphi will automatically create an interface unit (the interface name you entered + Intf ends, that is, MainIntf) and an interface Implementation Unit (the name is the interface name you entered + Impl, that is, MainImpl ). This empty WebService has been created.
4. Compile the WebService function for others to call. Here we will compile a simple example. Open the Interface Unit (MainIntf), after the Type, add the interface function after the interface declaration
"Function GetMsg (AMsg: string): String; stdcall;" must be followed by "stdcall ".
5. The declaration of the interface function has been completed. The following describes how to implement this function. Open the interface Implementation Unit (MainImpl ),
Write the declaration of the function in public, and write the implementation of the function after implement.
6. At this point, WebService has been completed. The next step is debugging. At the time of creation, Delphi has created a Unit1 and its form for us, referenced the Interface Unit (MainImpl) in Unit1, and then added a button in the form, in the Click Event of the button, call the WebService function you just wrote to debug the code.
Or use the THTTPRIO control.
7. After successful debugging, you can convert the Web App Debugger type to the ISAPI type. In fact, it is very easy to create an ISAPI-type WebService project, select New | Other | WebServices | SOAP Server Application | ISPA /..., The system prompts whether to select "yes" when creating an interface, enter the same interface name as the one you just entered, and save it, then, replace the interface unit and interface Implementation Unit in the WebService project of the Web App Debugger type that has been successfully debugged with the interface unit and interface Implementation Unit in the newly created ISAPI type project, open the ISAPI-type WebService and compile the dll. At this point, the ISAPI-type WebService is successfully created.
8. Publish an ISAPI-type WebService to IIS. Create a new site in IIS. When creating a site, set the execution permission to "script and executable file", copy the entire WebService project to the site folder, and start the site, this WebService is successfully published. If IIS is above 6.0, set "all unknown ISAPI extensions" to allow in Web service extensions,
For detailed settings, see the IIS Help documentation.
9. How to Use Delphi to call the WebService you just wrote. Enter the path of the site, for example, http: // 127.0.0.1/project2.dll, in the browser, and go to the project folder,
Open the dll description page, as shown in. The dll contains an interface function GetMsg, which is an interface function for others to call. Click "WSDL" to open the WSDL description page. Copy the URL http: // 127.0.0.1/project2.dll/wsdl/IMain of the page. This URL is used.
10. After obtaining the URL, create an Application, and call the WebService in the Application. Click New | Other | WebServices | WSDL Import in sequence. If you are prompted to enter the URL, enter the copied URL and click next and finish. At this time, Delphi will automatically add a unit, this unit is the unit that calls WebService. With this unit, we can call WebService. Reference this unit in Unit1, add a button, declare an interface object in the Click Event of the button, and then call GetMainIntf in the auto-generated unit (this method is automatically generated) the function assigns a value to this interface object, and then you can use this interface object to call the interface function.
Note: If the front-end uses the THTTPRIO control to connect,
SetHttp: // 127.0.0.1/project2.dll/wsdl/IMainAssignedWsdlLocationAttribute insteadURLAttribute