delphi call java webservice

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    btn1: TButton;
    edt1: TEdit;
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

where
  Form1: TForm1;

implementation

{$R *.dfm}

uses HelloService1;

procedure TForm1.btn1Click (Sender: TObject);
  was
   ows: HelloService;
  s: string;
 begin
 // 'http://localhost:8080/helloService/services/HelloService?wsdl';
   //ows := GetHelloService(true,'http://localhost:8081/wsdl/IMyData',nil);
   ows := GetHelloService(true,'http://localhost:8080/helloService/services/HelloService?wsdl',nil);
   //参数中可以使用配置的url
  s := ows.say('delphixe10 xxxx:');

  if length(s) <> 0 then
  begin
    edt1.Text:= s;
  end;

 over ;
than .





//导入wsdl文件后 自动生成的.pas文件
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL     : http://localhost:8080/helloService/services/HelloService?wsdl
//  >Import : http://localhost:8080/helloService/services/HelloService?wsdl>0
// Encoding : UTF-8
// Version  : 1.0
// (2018-09-03 00:55:03 - - $Rev: 69934 $)
// ************************************************************************ //

unit HelloService1;

interface

uses Soap.InvokeRegistry, Soap.SOAPHTTPClient, System.Types, Soap.XSBuiltIns;

const
  IS_REF  = $0080;


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://service
  // transport : http://schemas.xmlsoap.org/soap/http
  // style     : document
  // use       : literal
  // binding   : HelloServiceSoapBinding
  // service   : HelloServiceService
  // port      : HelloService
  // URL       : http://localhost:8080/helloService/services/HelloService
  // ************************************************************************ //
  HelloService = interface(IInvokable)
  ['{A2CB7213-47FF-E203-449D-D3EC4A92A153}']
    function  say(const name_: string): string; stdcall;
  end;

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


implementation
  uses System.SysUtils;

function GetHelloService(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): HelloService;
const
  defWSDL = 'http://localhost:8080/helloService/services/HelloService?wsdl';
  defURL  = 'http://localhost:8080/helloService/services/HelloService';
  defSvc  = 'HelloServiceService';
  defPrt  = 'HelloService';
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 HelloService);
    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;
  over ;
over ;


initialization
  { HelloService }
  InvRegistry.RegisterInterface(TypeInfo(HelloService), 'http://service', 'UTF-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(HelloService), '');
  InvRegistry.RegisterInvokeOptions(TypeInfo(HelloService), ioDocument);
  { HelloService.say }
  InvRegistry.RegisterMethodInfo(TypeInfo(HelloService), 'say', '',
                                 '[ReturnName="sayReturn"]');
  InvRegistry.RegisterParamInfo(TypeInfo(HelloService), 'say', 'name_', 'name', '');

end.





//HelloService.java
package service;
 
public class HelloService {
    public String say(String name) throws InterruptedException{
        return "hello worldxxx -----> "+name;
    }
}

Guess you like

Origin www.cnblogs.com/tobetterlife/p/12172975.html