用RO调用jave6的webservice
java6自带webservice开发功能非常便利。那么用d调用又如何。其实也非常简单。 这里体现懒汉的优势,用ro service builder 直接生成如下:
unit SignLibrary_Intf;
{----------------------------------------------------------------------------}
{ This unit was automatically generated by the RemObjects SDK after reading }
{ the RODL file associated with this project . }
{ }
{ Do not modify this unit manually, or your changes will be lost when this }
{ unit is regenerated the next time you compile the project. }
{----------------------------------------------------------------------------}
{$I RemObjects.inc}
interface
uses
{vcl:} Classes, TypInfo,
{RemObjects:} uROXMLIntf, uROClasses, uROClient, uROTypes, uROClientIntf;
const
{ Library ID }
LibraryUID = '{B0D81C3E-ADEA-40CC-8F17-9D8669D4FBDF}';
WSDLLocation = 'http://192.168.1.78:8080/lavasoft.ServiceServer?wsdl';
TargetNamespace = 'http://lavasoft/';
{ Service Interface ID's }
IServiceServerService_IID : TGUID = '{4160302F-5F1E-4424-89E8-950285727951}';
ServiceServerService_EndPointURI = 'http://192.168.1.78:8080/lavasoft.ServiceServer';
type
TSeekOrigin = Classes.TSeekOrigin; // fake declaration
{ Forward declarations }
IServiceServerService = interface;
{ IServiceServerService }
IServiceServerService = interface
['{4160302F-5F1E-4424-89E8-950285727951}']
function doSomething(const doSomething: UnicodeString): UnicodeString;
end;
{ CoServiceServerService }
CoServiceServerService = class
class function Create(const aMessage: IROMessage; aTransportChannel: IROTransportChannel): IServiceServerService;
end;
{ TServiceServerService_Proxy }
TServiceServerService_Proxy = class(TROProxy, IServiceServerService)
protected
function __GetInterfaceName:string; override;
function doSomething(const doSomething: UnicodeString): UnicodeString;
end;
implementation
uses
{vcl:} SysUtils,
{RemObjects:} uROEventRepository, uROSerializer, uRORes;
{ CoServiceServerService }
class function CoServiceServerService.Create(const aMessage: IROMessage; aTransportChannel: IROTransportChannel): IServiceServerService;
begin
Result := TServiceServerService_Proxy.Create(aMessage, aTransportChannel);
end;
{ TServiceServerService_Proxy }
function TServiceServerService_Proxy.__GetInterfaceName:string;
begin
Result := 'ServiceServerService';
end;
function TServiceServerService_Proxy.doSomething(const doSomething: UnicodeString): UnicodeString;
var
lMessage: IROMessage;
lTransportChannel: IROTransportChannel;
begin
lMessage := __GetMessage;
lTransportChannel := __TransportChannel;
lMessage.SetAttributes(lTransportChannel, ['InputImportedFromUrl', 'Location', 'OutputImportedFromUrl', 'SoapActionIsEmpty', 'SOAPInputNameOverride', 'SOAPOutputNameOverride', 'TargetNamespace'
, 'Type', 'Use', 'Wsdl'],
['lavasoft.ServiceServer?xsd=1', 'http://192.168.1.78:8080/lavasoft.ServiceServer', 'lavasoft.ServiceServer?xsd=1', '1', 'doSomething', 'doSomethingResponse', TargetNamespace
, 'SOAP', 'literal', WSDLLocation]);
try
lMessage.InitializeRequestMessage(lTransportChannel, 'SignLibrary', __InterfaceName, 'doSomething');
lMessage.Write('doSomething', TypeInfo(UnicodeString), doSomething, []);
lMessage.Finalize;
lTransportChannel.Dispatch(lMessage);
lMessage.Read('return', TypeInfo(UnicodeString), Result, []);
finally
lMessage.UnsetAttributes(lTransportChannel);
lMessage.FreeStream;
lMessage := nil;
lTransportChannel := nil;
end;
end;
initialization
RegisterProxyClass(IServiceServerService_IID, TServiceServerService_Proxy);
finalization
UnregisterProxyClass(IServiceServerService_IID);
end.
=================
看调用:
procedure TForm1.Button2Click(Sender: TObject); var myCoServiceServerService : IServiceServerService; begin myCoServiceServerService := CoServiceServerService.Create(ROSOAPMessage1,ROWinInetHTTPChannel1); edt1.Text := myCoServiceServerService.doSomething('12312'); end;
procedure TForm1.Button2Click(Sender: TObject); var myCoServiceServerService : IServiceServerService; begin myCoServiceServerService := CoServiceServerService.Create(ROSOAPMessage1,ROWinInetHTTPChannel1); edt1.Text := myCoServiceServerService.doSomething('12312'); end;
====================
结果如下 :

爽吧!
爽极了!