"Go" Delphi Call WebService Summary

Source: Internet
Author: User

Original: http://www.cnblogs.com/zhangzhifeng/archive/2013/08/15/3259084.html

Delphi called C # wrote the WebService

The Thttprio control in Delphi invokes the WebService written by C #.

Here are some of the problems I encountered while debugging:

1: Import WSDL file: file--new----Other----WebService---wsdlimporter---Enter the WSDL address: The following: http://127.0.0.1/WebService/ webservicecall.asmx?wsdl

Note the end of: '? WSDL ' cannot be less. Or you might say you can't find it.

2: Set the properties of the Thttprio control:

Assign http://127.0.0.1/webservice/webservicecall.asmx?wsdl to the URL property instead of to the Wsdllocation property.

3: The pass-through parameter is always empty on the Web service side:

Add the following code in the Declarations section of the imported interface unit:

Invregistry.registerinvokeoptions (TypeInfo (Service1Soap), iodocument);//The red part is the import interface name.

in the IIS Configure C # in written by WebService , sometimes the following error occurs:

--------------------------------------------------------
Parser Error message : It is an error to use a section registered as allowdefinition= ' machinetoapplication ' outside the application level. This error can be caused if the virtual directory is not configured as an application in IIS.
Source Error :
Secure authentication mode.
-
<authentication mode= "Windows"/>
<!--
If an unhandled error occurs during the execution of the request
------------------------------------------------------------------------------
Workaround:
Create an application in the virtual directory that you want to publish. Steps

Your site--Select the virtual directory you want to publish--right-click--Properties (tab)-------to the application---------and OK.

Then re-visit the page, should be OK.

Delphi 7 Build a test program

1. Create a new application:
2. Drag a button an edit and a Httprio (on the WebServices page) to the form;
3. Next:
file-> new-> other-> webservices-> WSDL Importer
Enter the WSDL file address and click Next to import
Save Unit Service1
4. Reference in Unit1 (Form1 unit file) Service1
5. HTTPRIO1 URL Property set to ' Http://localhost/WebService1/Service1.asmx?WSDL '

6. Add Form1 code as follows:

Unit Unit1;

Interface

Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls, Invokeregistry, Rio, soaphttpclient;
Type
TForm1 = Class (Tform)
Button1:tbutton;
Edit1:tedit;
Httprio1:thttprio;
Procedure Button1Click (Sender:tobject);
Private
{Private declarations}
Public
{Public declarations}
End
Var
Form1:tform1;
Implementation
Uses
Service1;

{$R *.DFM}
Procedure Tform1.button1click (Sender:tobject);
Begin
Edit1.text:= (HTTPRIO1 as Service1Soap). HelloWorld;
End
End.

if sometimes the test finds , or not? ....... may have the following problem,

in use VS2005 wrote the WebService class attribute in the Soaprpcserviceattribute attribute is available.
as below :
[SoapRpcService (Routingstyle=soapserviceroutingstyle.soapaction)]

Delphi Development and invocation of the WebService

The following describes how to write IIS published by ISAPI type of WebService .

1 , new| other| webservices| SOAP Server application| This is the first choice to build Web App Debugger type of WebService , because this type of WebService easy to debug, when we debug it, ready to publish and then convert this type to ISAPI type.

2 , after selecting the Web App Debugger , enter a ClassName, here we enter " Test "

3 , then Delphi will ask if you want to create the interface unit, select Yes, then enter the name of the interface, we enter Main,Delphi The Interface Unit ( the name of the interface name you entered is +intf end, that is, mainintf) and the unit that implements the interface (the name of the interface you entered +impl, or mainimpl). To this an empty WebService has been set up well.

4 , Next we'll write the WebService function for others to call . Here we write a simple example. Open the Interface unit (mainintf) after the Type , after the interface declaration, add the interface function

" function getmsg (amsg:string): string; stdcall; ", the function must be followed by the" stdcall ".

5 , the Declaration of the interface function has been completed, the following is 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 , to this, WebService finished writing. The next step is debugging. In our new building,Delphi has created a Unit1 and its form for us, in Unit1 andthen add a button to the form to invoke the button's Click event in theMainimpl WebService The function can be debugged, the code

or use Thttprio controls

7 , after debugging successful, you can turn the type, Web App Debugger type to ISAPI The type is simple, so let's start by building a ISAPI type of WebService Project, select new| other| webservices| SOAP Server application| ispa/ ..., if you are prompted to select "Yes" when creating the interface, then enter the same interface name as you did, then save it and then debug the successful Web App Debugger type of WebService interface units and interfaces in the project implement unit replication replace the newly created ISAPI interface Units and interface implementation units in a type project, and then open ISAPI type of WebService , compile Build DLL . The WebService for the ISAPI type was successfully established.

8 , the ISAPI type of WebService Publish to IIS on. Create a new site in IIS, set the Execute permissions to "scripts and executables" when new , copy the entire project WebService to the site folder, start the site, the WebService even if the release was successful, if IIS is a 6.0 the above attention in Web the service extension will "all unknown ISAPI extended to allow,

Specific settings can be found in the IIS Help documentation.

9 , how to use Delphi The call was just written WebService . In the browser, enter the path of the site just now, such as: http://127.0.0.1/project2.dll, the browser goes to the folder where the project

Open as shown in the DLL description page, which DLL there are interface functions in the getmsg , they are all interface functions for others to call. Click wsdl to open the WSDL description page and copy the URL of the page HTTP://127.0.0.1/ Project2.dll/wsdl/imain, this is the URL we need to use.

Ten , After getting the URL, create a new application, and we'll call in this application just WebService. Click new| other| webservices| WSDL import, as prompted to enter the URL, we enter the URL just copied, click next,finish, at this time Delphi a cell is added automatically, and the cell is called WebService unit, and with this unit we can call WebService up. Reference the cell in Unit1, add a button, declare an interface object in the button's click event, and then call the getmainintf in the auto-generated cell (The method is automatically generated) the function assigns a value to the interface object, and then the interface function can be invoked with this interface object.

Note: If the foreground uses Thttprio control to connect,

Assign Http://127.0.0.1/project2.dll/wsdl/IMain to the Wsdllocation property instead of to the URL property. This is not the same as calling C #

Delphi called JAVA wrote the WebService

Java write the service-side WebService

Development environment

MyEclipse 6.5 + jdk6.0 +tomcat 6.0 + Axis2

Specific development steps do not speak, online, will only encounter a few problems said:

1. installation Axis2 the latest version of the plugin that I use when online is 1.6.1 , download the following two plugins

Service Archive Wizard-eclipse Plug-in

Code Generator Wizard-eclipse Plug-in

Install the online method to copy directly to the plugins directory, in MyEclipse new---->other does not appear the following interface

There is no way to find the Internet, and later found the following version, is

axis2_codegen_wizard_1.3.0

axis2_service_archiver_1.3.0

Direct copy to the plugins directory can be;

Analysis: It is estimated that the Eclpise version in the MyEclipse version is low, not installed in the high version of 1.6.1, anyway, the lower version is good to use;

2, in the MyEclipse, development, if using AXIS2 service archiver generation services, you need to put the project properties of Java Compiler--->compiler compliance Level: Instead of 5.0, my default is 6.0;

or the last Load not out class in the method;

3 , if you need some Jar files, such as those related to database connections Jar , publish to Tomcat in the middle of the day, you need to copy these files to Webapps\axis2\web-inf\lib under;

4 , using Delphi 7 called Axis2 wrote the WebService , Import WSDL when there is no interface description, it may be Delphi version is too low, so use the Delphi The import generates an interface file and then uses the Delphi 7 can also be in;

5 , set the properties of the Thttprio control, assign the WSDL to the URL property, and adjust C # as

Recommended to use a high version of development webservice, such as 2007,2010, Delphi 7 has a lot of trouble

"Go" Delphi Call WebService Summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.