六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 333|回复: 0

Delphi调用Java WebService

[复制链接]

升级  34.33%

93

主题

93

主题

93

主题

举人

Rank: 3Rank: 3

积分
303
 楼主| 发表于 2012-12-10 13:14:44 | 显示全部楼层 |阅读模式
Delphi调用Java WebService

<div id="cnblogs_post_body">刚用Java做了个WebService,并且在Java中调用成功, WebService在Delphi中同样可以调用。
在Delphi中新建一个工程,然后点击Component->Import WSDL...

WSDL的URL以及该WebService的内容请参考:
http://www.cnblogs.com/GarfieldTom/archive/2012/09/14/2684361.html

使用缺省设置,生成引用文件:

<div class="cnblogs_code">// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL     : http://localhost:8030/garfield.MyJ6WebService?wsdl
//  >Import : http://localhost:8030/garfield.MyJ6WebService?wsdl>0
//  >Import : http://localhost:8030/garfield.MyJ6WebService?xsd=1
// Encoding : UTF-8
// Version  : 1.0
// (2012-09-14 9:39:27 - - $Rev: 25127 $)
// ************************************************************************ //

unit garfield;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;

const
  IS_OPTN = $0001;
  IS_UNQL = $0008;


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 Embarcadero types; however, they could also
  // indicate incorrect WSDL documents that failed to declare or import a schema type.
  // ************************************************************************ //
  // !:string          - "http://www.w3.org/2001/XMLSchema"[Gbl]



  // ************************************************************************ //
  // Namespace : http://garfield/
  // transport : http://schemas.xmlsoap.org/soap/http
  // style     : document
  // binding   : MyJ6WebServicePortBinding
  // service   : MyJ6WebServiceService
  // port      : MyJ6WebServicePort
  // URL       : http://localhost:8030/garfield.MyJ6WebService
  // ************************************************************************ //


  MyJ6WebService = interface(IInvokable)
  ['{73C2D68E-4BCE-E05A-3459-8E5DFD772DC1}']
    function  SayHello(const arg0: string): string; stdcall;
  end;

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


implementation
  uses SysUtils;

function GetMyJ6WebService(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): MyJ6WebService;
const
  defWSDL = 'http://localhost:8030/garfield.MyJ6WebService?wsdl';
  defURL  = 'http://localhost:8030/garfield.MyJ6WebService';
  defSvc  = 'MyJ6WebServiceService';
  defPrt  = 'MyJ6WebServicePort';
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 MyJ6WebService);
    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(MyJ6WebService), 'http://garfield/', 'UTF-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(MyJ6WebService), '');
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表