zoukankan      html  css  js  c++  java
  • 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哇哈哈+ '));

    运行结果

     
  • 相关阅读:
    Atitit 查找算法 艾提拉大总结 目录 1. 查找算法分类 1 1.1. 简单查找算法之折半查找、插值查找、斐波那契查找 1 1.2. 按照数据结构查找法分类 hash 表 1 2. 第8章查找
    Atitit 数据结构与常见文件元数据结构 目录 1. 分类 内部数据结构与外部存储数据结构 1 2. 编程语言内部数据结构 (堆栈 树 图等 1 2.1. 数据结构 (集合,列表,tree,map
    关于“王福朋详解petshop4.0系列视频教程”的开放下载问题
    《王福朋petshop4.0视频教程》新浪视频地址
    《petshop4.0视频教程》在线看
    《微软petshop4.0视频教程》 开放下载了!!!
    看马克扎克伯格创建facebook——电影《社交网络》观后感
    《王福朋petshop4.0视频教程》新浪视频(高清)
    当ListView控件在后台绑定数据源时,用DataPager控件分页需要注意的问题
    《王福朋petshop4.0视频教程》下载通知
  • 原文地址:https://www.cnblogs.com/usegear/p/2805427.html
Copyright © 2011-2022 走看看