java webservice调用中参数null的问题
package lavasoft; import javax.jws.WebService; import javax.xml.ws.Endpoint; /** * Java6开发WebService入门 * * @author usegear 2009-11-13 16:10:44 */ @WebService public class ServiceServer { /** * Web服务中的业务方法 * * @return 一个字符串 */ public String doSomething(String Myvar ){ System.out.println(Myvar); return (Myvar+" Hello Java6 WebService!你好这个世界!"); } public static void main(String[] args) { //发布一个WebService Endpoint.publish("http://192.168.1.78:8080/lavasoft.ServiceServer", new ServiceServer()); } }
调用接口:
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 = '{9BE13FC5-589E-4A60-9910-CA90F4E2C153}'; WSDLLocation = 'http://192.168.1.78:8080/lavasoft.ServiceServer?wsdl'; TargetNamespace = 'http://lavasoft/'; { Service Interface ID's } IServiceServerService_IID : TGUID = '{E96358FB-544D-4AE6-B9F5-FAAC000BFC9A}'; ServiceServerService_EndPointURI = 'http://192.168.1.78:8080/lavasoft.ServiceServer'; type TSeekOrigin = Classes.TSeekOrigin; // fake declaration { Forward declarations } IServiceServerService = interface; { IServiceServerService } IServiceServerService = interface ['{E96358FB-544D-4AE6-B9F5-FAAC000BFC9A}'] function doSomething(const arg0: 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 arg0: 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 arg0: 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', 'ioDocument', WSDLLocation]); // , 'SOAP', 'literal', WSDLLocation]); //ioDocument try lMessage.InitializeRequestMessage(lTransportChannel, 'SignLibrary', __InterfaceName, 'doSomething'); lMessage.Write('arg0', TypeInfo(UnicodeString), arg0, []); 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.
ioDocument和'literal'注意选择,why?你知道请告诉我。
由d本身通过wsdl进行import的单元如下
// ************************************************************************ // // The types declared in this file were generated from data read from the // WSDL File described below: // WSDL : http://192.168.1.78:8080/lavasoft.ServiceServer?wsdl // >Import : http://192.168.1.78:8080/lavasoft.ServiceServer?wsdl:0 // >Import : http://192.168.1.78:8080/lavasoft.ServiceServer?xsd=1 // Encoding : UTF-8 // Version : 1.0 // (2012-12-06 8:58:04 - - $Rev: 10138 $) // ************************************************************************ // unit lavasoft; 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 Borland 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://lavasoft/ // transport : http://schemas.xmlsoap.org/soap/http // style : document // binding : ServiceServerPortBinding // service : ServiceServerService // port : ServiceServerPort // URL : http://192.168.1.78:8080/lavasoft.ServiceServer // ************************************************************************ // ServiceServer = interface(IInvokable) ['{0BEB1075-6464-A6B0-12F3-8BAF286836C6}'] function doSomething(const arg0: WideString): WideString; stdcall; end; function GetServiceServer(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): ServiceServer; implementation uses SysUtils; function GetServiceServer(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): ServiceServer; const defWSDL = 'http://192.168.1.78:8080/lavasoft.ServiceServer?wsdl'; defURL = 'http://192.168.1.78:8080/lavasoft.ServiceServer'; defSvc = 'ServiceServerService'; defPrt = 'ServiceServerPort'; 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 ServiceServer); 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(ServiceServer), 'http://lavasoft/', 'UTF-8'); InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ServiceServer), ''); //InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceServer), ioDocument); //上一句注释掉。why?你知道请告诉我
//ioLiteral // InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceServer), ioLiteral); end.
调用:
procedure TForm1.Button2Click(Sender: TObject); var myCoServiceServerService : IServiceServerService; mysre : WideString; begin myCoServiceServerService := CoServiceServerService.Create(ROSOAPMessage1,ROWinInetHTTPChannel1); mysre := '12312'; edt1.Text := myCoServiceServerService.doSomething('hello 这个万恶的世界'); end;
应用d的import的接口单元调用:
ShowMessage(GetServiceServer().doSomething('hello usegear哇哈哈+ '));
运行结果