首先取得java-webservice服务器端地址。我的是:http://localhost:8080/mywebservice/services/mywebservice?wsdl
然后打开delphi7,file-new-other:选择WebService选项卡,在选择WSDLImporter
,在弹出的界面中输入java-webservice地址。点击Next-finish.会生成一个.pas的webservice文件,
生成的代码如下:
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://localhost:8080/mywebservice/services/mywebservice?wsdl
// Encoding : UTF-8
// Version : 1.0
// (2011-7-21 10:17:02 - 1.33.2.5)
// ************************************************************************ //
unit mywebservice;
interface
uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;
type
// ************************************************************************ //
// The following types, referred to in the WSDL document are not being represented
// in this file. They are either aliases[@] of other types represented or were referred
// to but never[!] declared in the document. The types from the latter category
// typically map to predefined/known XML or Borland types; however, they could also
// indicate incorrect WSDL documents that failed to declare or import a schema type.
// ************************************************************************ //
// !:int - "http://www.w3.org/2001/XMLSchema"
// !:string - "http://www.w3.org/2001/XMLSchema"
// ************************************************************************ //
// Namespace : http://server
// transport : http://schemas.xmlsoap.org/soap/http
// style : document
// binding : mywebserviceHttpBinding
// service : mywebservice
// port : mywebserviceHttpPort
// URL : http://localhost:8080/mywebservice/services/mywebservice
// ************************************************************************ //
mywebservicePortType = interface(IInvokable)
['{56F18980-71B1-FAC0-BFF5-569F621A8591}']
function add(const a: Integer; const b: Integer): Integer; stdcall;
function sayHello(const name: WideString): WideString; stdcall;
end;
function GetmywebservicePortType(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): mywebservicePortType;
implementation
function GetmywebservicePortType(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): mywebservicePortType;
const
defWSDL = 'http://localhost:8080/mywebservice/services/mywebservice?wsdl';
defURL = 'http://localhost:8080/mywebservice/services/mywebservice';
defSvc = 'mywebservice';
defPrt = 'mywebserviceHttpPort';
var
RIO: THTTPRIO;
begin
Result := nil;
if (Addr = '') then
begin
if UseWSDL then
Addr := defWSDL
else
Addr := defURL;
end;
if HTTPRIO = nil then
RIO := THTTPRIO.Create(nil)
else
RIO := HTTPRIO;
try
Result := (RIO as mywebservicePortType);
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
end else
RIO.URL := Addr;
finally
if (Result = nil) and (HTTPRIO = nil) then
RIO.Free;
end;
end;
initialization
InvRegistry.RegisterInterface(TypeInfo(mywebservicePortType), 'http://server', 'UTF-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(mywebservicePortType), '');
InvRegistry.RegisterInvokeOptions(TypeInfo(mywebservicePortType), ioDocument);
InvRegistry.RegisterExternalParamName(TypeInfo(mywebservicePortType), 'add', 'out_', 'out');
InvRegistry.RegisterExternalParamName(TypeInfo(mywebservicePortType), 'sayHello', 'out_', 'out');
end.
新建一个form窗体,拖入一个Button和一个edit控件。
在窗体的uses部分加入InvokeRegistry, Rio, SOAPHTTPClient, mywebservice。
为Button添加click事件。
procedure TForm1.Button1Click(Sender: TObject);
var
server:mywebservicePortType;//此处为delphi生成的java-webservice的方法名。
aa:string;
begin
server:=GetmywebservicePortType(true,'',nil);//delphi生成的方法
showmessage(server.sayHello(Edit1.Text));//调用java-webservice的sayHello()方法。
end;
到此,delphi调用java的webservice服务器端程序示例已经完成。
- 大小: 52 KB
- 大小: 21.8 KB
分享到:
相关推荐
delphi调用Webservice实现数据库的增删改查功能完整的源代码示例,此为原创作品。
SatJni是C++编写的动态链接库,实现了C#,PB,Delphi,VB,VC等对Java的调用,能让你很容易地调用成熟的java类库和第三方...示例中演示了PB调用webservice服务(无需代理对象)得到电话号码和天气信息、调用Base64和MD5等。
C#直接调用java类(jar或.class文件),无需转化为.net组件,更快速、稳定 SatJni是C++编写的动态链接库,实现了...示例中演示了通过java调用webservice服务(无需代理对象)得到电话号码和天气信息、调用Base64和MD5等。
用Delphi实现Web Service的简单示例
亿美短信_SDK应用接口官方没有提供Delphi的webservice接口调用示例代码,我根据C#的例子书写了这个,与大家分享
SatJni是C++编写的动态链接库,实现了C#,PB,Delphi,VB,VC等对Java的调用,能让你很容易地调用成熟的java类库和...示例中演示了通过java调用webservice服务(无需代理对象)得到电话号码和天气信息、调用Base64和MD5等。
通过 Dx10.1封装顺丰webservice接口,然后安装顺丰加密转换要求实现相关电子面单下单功能。(备注:我是D7调用,因此才需要使用Dx10.1做成DLL,如果直接使用Dx10.1则直接调用即可)
Delphi THTTPRIO调用wsld接口,包含设置Head Authorization认证方式
ABBRIMAGE 缩略图 ADO OLE DB数据库 API Windows API封装 ...WEBSERVICE WEB服务调用与创建 WORDOUTLINE WORD大纲 WORDPLUGIN WORD插件(最新功能,如需要请联系作者,此示例需要购买) ZIP 压缩与解压缩功能
DOM的XML操作可参考的示例:http://www.w3school.com.cn/xmldom/met_document_getelementsbytagname.asp 2)在IE下面还是要通过loadXML来转responseText; 3)xml加载后异步属性设置; 4)命名空间处理等问题; ...
dephi调用WebService的示例程序,给初学者带来帮助