delphi客户端调服务器端的java webservice如何在参数中传对象?
我试过java返回一个对象到delphi端没问题,可反过来,delphi通过参数传一个对象到java,java端得到的对象值变为空,不知道是不是delphi这边设置或者对象注册方面有问题,究竟该怎么解决,请各位大虾指教,小妹在这多谢各位了!
delphi根据java wsdl文件生成的webservice文件内容如下:
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL     : http://10.3.8.92:8080/Service/ws/IFC?wsdl
// Encoding : UTF-8
// Codegen  : [wfDebug,wfServer,wfAmbiguousComplexTypesAsArray,wfOutputLiteralTypes,wfIgnoreSchemaErrors,wfUseSerializerClassForAttrs]
// Version  : 1.0
// (2009-4-19 10:36:15 - 1.33.2.5)
// ************************************************************************ //unit IFC;interfaceuses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;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"
  // !:dateTime        - "http://www.w3.org/2001/XMLSchema"
  // !:int             - "http://www.w3.org/2001/XMLSchema"
  // !:decimal         - "http://www.w3.org/2001/XMLSchema"
  // !:boolean         - "http://www.w3.org/2001/XMLSchema"
  Test                 = class;                 { "http://xxx.xxx.xxx.com" }
    // ************************************************************************ //
  // Namespace : http://http://xxx.xxx.xxx.com
  // Serializtn: [xoLiteralParam]
  // ************************************************************************ //
   Test = class(TRemotable)
    private
      Fuser: WideString;
    public
      constructor Create; override;
    published
      property user: WideString read Fuser write Fuser;
    end;
  // ************************************************************************ //
  // Namespace : http://remote.interfaces.xxx.xxx.com
  // transport : http://schemas.xmlsoap.org/soap/http
  // style     : rpc
  // binding   : IFCHttpBinding
  // service   : IFC
  // port      : IFCHttpPort
  // URL       : http://10.3.8.92:8080/Service/ws/IFC
  // ************************************************************************ //
  IFCPortType = interface(IInvokable)
  ['{952A77FA-0414-2644-C2D3-FB6469EE208A}']
  function  TestB(const in0: Test): WideString; stdcall;
implementationtype  IFCPortTypeImpl = class(TInvokableClass, IFCPortType)
  public
    { IFCPortType }
    function  TestB(const in0: Test): WideString; stdcall;function IFCPortTypeImpl.TestB(const in0: Test): WideString;
begin
  { TODO - Implement method TestB }
end;constructor Test.Create;
begin
  inherited Create;
  FSerializationOptions := [xoLiteralParam];
end;initialization
  InvRegistry.RegisterInterface(TypeInfo(IFCPortType), 'http://remote.interfaces.pastoral.shiji.com', 'UTF-8');
  InvRegistry.RegisterInvokableClass(IFCPortTypeImpl);
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(IFCPortType), '');
  RemClassRegistry.RegisterXSClass(Test, 'http://entity.pastoral.shiji.com', 'Test');
  RemClassRegistry.RegisterSerializeOptions(Test, [xoLiteralParam]);
end;

解决方案 »

  1.   

    在Unit IFC中的initialization 处加以下这句话!InvRegistry.RegisterInvokeOptions(TypeInfo(IFCPortType), ioDocument);
      

  2.   


    谢谢楼上的,我试过了不行,也听一些大虾说RPC方式是不需要这句的
      

  3.   

    补一下:
       调用别的公司Web Service ,一帮脑残的人用对象做参数和返回.....
    随便到网上查一下,只要考虑一点点通用性,就应该将数据作为xml格式的字符串来传递啊.
    鄙视一下
      

  4.   

    个人建议,全部由XML格式代替对象,这才“通用”
    2种语言,在沟通上,最好需要有个“介质”我个人觉得 字符串和 XML 是最好的选择,虽然稍微麻烦了一些,但是,绝对不出错!
      

  5.   

    问题4:服务端得到的参数都为空值
    解决:检查一下引入的WebService单元的最后三行是否如下
    initialization
      InvRegistry.RegisterInterface(TypeInfo(YourWebServiceSoap), 'http://tempuri.org/', 'utf-8');
      InvRegistry.RegisterDefaultSOAPAction(TypeInfo(YourWebServiceSoap), 'http://tempuri.org/%operationName%');
      InvRegistry.RegisterInvokeOptions(TypeInfo(YourWebServiceSoap), ioDocument);//这一行有时会没有
    end.
    这一行 InvRegistry.RegisterInvokeOptions(TypeInfo(YourWebServiceSoap), ioDocument);有时候没有的。举个例子,当我们的WebService的其中一个方法有参数的类型为DataSet时,单元文件的最后几行是这样的
    initialization
      InvRegistry.RegisterInterface(TypeInfo(YourWebServiceSoap), 'http://tempuri.org/', 'utf-8');
      InvRegistry.RegisterDefaultSOAPAction(TypeInfo(YourWebServiceSoap), 'http://tempuri.org/%operationName%');
      RemClassRegistry.RegisterXSClass(GetDataSetResult, 'http://tempuri.org/', GetDataSetResult);
      RemClassRegistry.RegisterXSClass(updateSet, 'http://tempuri.org/', 'updateSet');
    end.
    这时,服务端接收到的所有参数都为null;这里你所手工在中间加入上面所提到的那一行。
      

  6.   

    虽然我不大懂,但是也要说一句:
    首先,To: Cnapollo :WebService传递对象的本质就是传递XML文本
    难道你真的以为WebService传递的是序列化了的对象?其次要说的是:java的WebService中的命名空间的问题
    从你上面的WSDL文件来看,命名空间应该是:http://tempuri.org/
    这个是默认的命名空间,一般在真正开发的时候会修改,java中最后的命名空间实际上就是服务器类所在的包我以前用java写过WebService的简单例子,即使客户端用java来写,如果客户端包的位置(也就是命名空间)和服务器
    不一致的话,那么,也会出现对象为空,或者访问了没任何返回的情况。Delphi中好像没有包这个说法,我也不知道如何将Delphi中的命名空间修改。
    但是建议你修改initialization 下面的凡是引用到命名空间的地方。让他和服务器的命名空间一致。
    服务器的命名空间应该在服务器的WSDL文件中找的到。
    再加上上面几位高手的方法或许就成功了呢!另外,D7的WebService服务器被客户端调用的时候,又一些BUG。
    比如:时间类型的数据的转化,NTDLL.DLL的错误,这些需要修改D7部分单元的代码,在重新编译。
    我所知道的就这些。
      

  7.   

    看在楼主的结贴率上,还想再说一句:
    Java里面支持泛型,DELPHI不支持。
    如果遇到集合类的时候,DELPHI会生成数组,这样的话,发送过去的对象JAVA也是无法解析的。以后想到什么再说了。
      

  8.   

    我以前也碰到过不过我解决了,忘了怎么处理的,环境我也清掉了JAVA我是用cxf写的
      

  9.   

    最后是怎么解决的嘛,我也遇到了类似的问题:刚开始时
    InvRegistry.RegisterInvokeOptions(TypeInfo(TestWebservice), ioLiteral ); ------报错cannot find dispatch method for{null}terminalNo using "payload Qname-based dispatcher" 然后修改InvRegistry.RegisterInvokeOptions(TypeInfo(TestWebservice), ioDocument); ------就是把 ioLiteral 改成 ioDocument,
    现在不报错,可是 服务端收到的参数是null , 这是什么原因呢? 等待高手...
    -------Delphi客户端调用服务端的java webservice   
      

  10.   

    刚才调用成功了,我只是把InvRegistry.RegisterInvokeOptions(TypeInfo(TestWebservice), ioDocument);  注释掉
    或者改成不是ioDocument和ioLiteral   都可以,具体为什么,我现在不知道,还请高手解答一下哈