基金评论家kenter博客

欢迎进入基金评论家kenter博客,有金融股票基金问题或意见请留言反馈,谢谢您的参与。

525个出面博客,你建立了几个? »

delphi7编写java为服务的webservice客户端

   由于社保局的升级与公司的需要,要用delphi写个调用webservice的东西

   由于之前同事都不是很精通那个方面,所以那突破技术的那苦力活又落在我身上了

  社保局那边是用java方面的J2EE架构,另外提供了一个Webservice的接口出来让我们调用,其中还设计到了签名证书,TMD真麻烦。

  现在证书还没拿到手,先用delphi7测试个例子

  首先我自己模拟了一下java的webservice的模式,用myeclipse6写了一个基于Xfire的websercive ,用的也是helloWorld的经典例子,呵呵,加入tomcat,启动服务,OK。

 下面轮到用delphi写客户端了,这个是我们的主题,

1.新建Project --> Application;

2.New-->Other-->WebService-->WSDL Importer,选择WebService服务的WSDL描述文件,也可选择WSDL文件的URL,填写“http://localhost:8080/HelloWorldService/services/HelloWorld?wsdl”;

3.单击“Finish”按钮,生成WSDL文件对应*.pas单元文件;

文件内容具体如下

 

unit HelloWorld;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;

type


  HelloWorldPortType = interface(IInvokable)
  ['{7F30309F-3B9E-B482-BF0B-5A57A208D8D1}']
    function  example(const in0: WideString): WideString; stdcall;
  end;

function GetHelloWorldPortType(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): HelloWorldPortType;


implementation

function GetHelloWorldPortType(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): HelloWorldPortType;
const
  defWSDL = 'http://localhost:8080/HelloWorldService/services/HelloWorld?wsdl';
  defURL  = 'http://localhost:8080/HelloWorldService/services/HelloWorld';
  defSvc  = 'HelloWorld';
  defPrt  = 'HelloWorldHttpPort';
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 HelloWorldPortType);
    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(HelloWorldPortType), 'http://hellows', 'UTF-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(HelloWorldPortType), '');
  InvRegistry.RegisterInvokeOptions(TypeInfo(HelloWorldPortType), ioDocument);
  InvRegistry.RegisterExternalParamName(TypeInfo(HelloWorldPortType), 'example', 'out_', 'out');

end.

最后一步测试调用代码如下

procedure TForm1.btn1Click(Sender: TObject);
var
  he : HelloWorldPortType;
  st : string;
begin
    he := GetHelloWorldPortType();
    st := he.example('kenter');
    ShowMessage(st);
end;

好的 测试成功

 

  • 相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Devo Build 80201

Copyright 0756-zh.com 珠海交友伴游网.