Delphi调用java写的webservice接口传参为NULL(100)

  • 主题发起人 主题发起人 lzh1983
  • 开始时间 开始时间
L

lzh1983

Unregistered / Unconfirmed
GUEST, unregistred user!
生成的webservice接口单元unit PDADataExchangeWebService1;interfaceuses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;type ParamInfo = class; { "http://jssupervise.com/wsjdWeb/webService/PDADataExchangeWebService" } MyRequestParameter10 = class; { "http://jssupervise.com/wsjdWeb/webService/PDADataExchangeWebService" } ReturnMessage = class; { "http://jssupervise.com/wsjdWeb/webService/PDADataExchangeWebService" } MyResponseMessage10 = class; { "http://jssupervise.com/wsjdWeb/webService/PDADataExchangeWebService" } ParamInfo = class(TRemotable) private FloginId: WideString; Fpassword: WideString; FdataTime: WideString; Fdata: TByteDynArray; published property loginId: WideString read FloginId write FloginId; property password: WideString read Fpassword write Fpassword; property dataTime: WideString read FdataTime write FdataTime; property data: TByteDynArray read Fdata write Fdata; end; MyRequestParameter10 = class(TRemotable) private FparamInfo: ParamInfo; public constructor Create; override; destructor Destroy; override; published property paramInfo: ParamInfo read FparamInfo write FparamInfo; end; ReturnMessage = class(TRemotable) private Fstatus: WideString; Fmsg: WideString; Fdata: TByteDynArray; FdataTime: WideString; published property status: WideString read Fstatus write Fstatus; property msg: WideString read Fmsg write Fmsg; property data: TByteDynArray read Fdata write Fdata; property dataTime: WideString read FdataTime write FdataTime; end; MyResponseMessage10 = class(TRemotable) private Freturn: ReturnMessage; public constructor Create; override; destructor Destroy; override; published property return: ReturnMessage read Freturn write Freturn; end; PDADataExchangeWebService = interface(IInvokable) ['{19B04096-E0D3-B775-6C44-9415864CC727}'] function canConnect(const parameters: MyRequestParameter10): MyResponseMessage10; stdcall; end;function GetPDADataExchangeWebService(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): PDADataExchangeWebService;implementationfunction GetPDADataExchangeWebService(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): PDADataExchangeWebService;const defWSDL = 'http://192.168.0.103:8080/wsjdWeb/wsjdWebService/PDADataExchangeWebService?wsdl'; defURL = 'http://192.168.0.103:8080/wsjdWeb/wsjdWebService/PDADataExchangeWebService'; defSvc = 'PDADataExchangeWebServiceImplService'; defPrt = 'PDADataExchangeWebServicePort';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; RIO.HTTPWebNode.UseUTF8InHeader := true; try Result := (RIO as PDADataExchangeWebService); 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;constructor MyRequestParameter10.Create;begin inherited Create; FSerializationOptions := [xoLiteralParam];end;destructor MyRequestParameter10.Destroy;begin if Assigned(FparamInfo) then FparamInfo.Free; inherited Destroy;end;constructor MyResponseMessage10.Create;begin inherited Create; FSerializationOptions := [xoLiteralParam];end;destructor MyResponseMessage10.Destroy;begin if Assigned(Freturn) then Freturn.Free; inherited Destroy;end;initialization InvRegistry.RegisterInterface(TypeInfo(PDADataExchangeWebService), 'http://jssupervise.com/wsjdWeb/webService/PDADataExchangeWebService', 'UTF-8'); InvRegistry.RegisterDefaultSOAPAction(TypeInfo(PDADataExchangeWebService), ''); //InvRegistry.RegisterInvokeOptions(TypeInfo(PDADataExchangeWebService), ioDocument); InvRegistry.RegisterInvokeOptions(TypeInfo(PDADataExchangeWebService), ioLiteral); RemClassRegistry.RegisterXSClass(ParamInfo, 'http://jssupervise.com/wsjdWeb/webService/PDADataExchangeWebService', 'ParamInfo'); RemClassRegistry.RegisterXSClass(MyRequestParameter10, 'http://jssupervise.com/wsjdWeb/webService/PDADataExchangeWebService', 'MyRequestParameter10'); RemClassRegistry.RegisterSerializeOptions(MyRequestParameter10, [xoLiteralParam]); RemClassRegistry.RegisterXSClass(ReturnMessage, 'http://jssupervise.com/wsjdWeb/webService/PDADataExchangeWebService', 'ReturnMessage'); RemClassRegistry.RegisterXSClass(MyResponseMessage10, 'http://jssupervise.com/wsjdWeb/webService/PDADataExchangeWebService', 'MyResponseMessage10'); RemClassRegistry.RegisterSerializeOptions(MyResponseMessage10, [xoLiteralParam]); end.Delphi调用的单元unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, PDADataExchangeWebService1, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } FParamInfo: ParamInfo; function canConnect(const param: MyRequestParameter10): MyResponseMessage10; end;var Form1: TForm1;implementation{$R *.dfm}function TForm1.canConnect(const param: MyRequestParameter10): MyResponseMessage10;begin Result := GetPDADataExchangeWebService.canConnect(param);end;procedure TForm1.Button1Click(Sender: TObject);var vRMsg: MyResponseMessage10; vMRP: MyRequestParameter10;begin FParamInfo := ParamInfo.Create; FParamInfo.loginId := 'admin'; FParamInfo.password := '8888'; FParamInfo.dataTime := '2010-10-22'; vMRP := MyRequestParameter10.Create; vMRP.paramInfo := FParamInfo; vRMsg := canConnect(vMRP); ShowMessage(vRMsg.return.status + vRMsg.return.msg);end;end.调用时老是提示传入的参数为空,请各路高手指教,不胜感激!
 
难道没人懂吗????
 
调试一下,看你发出的XML与对方接收到的XML是怎么样的然后可以看出是不是你的XML格式对方无法识别或者直接用高版本的delphi试一下,如果可以,说明是delphi的问题,可以升级版本或改一下vcl.
 
发出去的格式是以下这样的,接口那边解析不了,提示参数值为NULL<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Body><MyRequestParameter10 xmlns="http://jssupervise.com/wsjdWeb/webService/PDADataExchangeWebService"><paramInfo><loginId>admin</loginId><password>8888</password><dataTime>2010-10-22</dataTime><data></data></paramInfo></MyRequestParameter10></SOAP-ENV:Body></SOAP-ENV:Envelope>人为的改成以下格式就可以成功<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Body><NS2:MyRequestParameter10 xmlns:NS2="http://jssupervise.com/wsjdWeb/webService/PDADataExchangeWebService"><paramInfo><loginId>admin</loginId><password>8888</password><dataTime>2010-10-22</dataTime><data></data></paramInfo></NS2:MyRequestParameter10></SOAP-ENV:Body></SOAP-ENV:Envelope>两者的区别就是后者有3个地方多了NS2请问vcl怎么修改,谢谢!
 
这个是Delphi自动生成的,位置也是自动生成的
 
具体怎么改已经不大记得了,你可以打开Debug DCU选项,然后跟踪生成XML的代码,把相关地方改掉就是了。有可能是OPToSOAPDomConv.pas等单元。还有一个办法,如果你的接口不算复杂,可以自己构造XML发过去,然后解析返回的XML,这也是可行的,直接用IdHttp即可。
 
Debug DCU选项在哪呢,D6有吗?
 
我在VS2008中写WEB服务用DELPHI调用遇到过这种问题。可能的问题和解决办法如下:1、如果是Win2003操作系统,则检查“我的电脑”->右键->属性->高级->(性能)设置->数据执行保护,如果是选择第二项则会出现这种问题,而且调用Web服务还会报内存错误。这里选择第一项"只为关键的Windows程序的服务启用数据保护",重新启动计算机即可。2、如果使用D6,请安装Update2补丁。3、如果不是以上问题,请在生成的Web服务单元中。 InvRegistry.RegisterDefaultSOAPAction(TypeInfo(PDADataExchangeWebService), ''); //InvRegistry.RegisterInvokeOptions(TypeInfo(PDADataExchangeWebService), ioDocument); InvRegistry.RegisterInvokeOptions(TypeInfo(PDADataExchangeWebService), ioLiteral);把注释的那一行去掉,那个必须有。否则传递过去的值肯定为空。VS2008中就存在这个问题。我记得是因为在数据传递过程中有两种不同的方式,而其中一种就是Document(文档)模式。在VS中默认是这一种,但是在D7中默认不是,所以传递的值为空。所以在D7中必须加这//InvRegistry.RegisterInvokeOptions(TypeInfo(PDADataExchangeWebService), ioDocument);这一行。
 
InvRegistry.RegisterInvokeOptions(TypeInfo(PDADataExchangeWebService), ioLiteral);------------没调用过Java的,难道这一句要放在最后?跟踪Delphi代码,重点TOPToSoapDomConvert类,看它如何生成包的Body的。---还没搞定啊。
 
查看了一下XMLIntf单元下的函数:function AddChild(const TagName, NamespaceURI: DOMString; GenPrefix: Boolean = False; Index: Integer = -1): IXMLNode; overload;如果:GenPrefix=False,就是你要的。跟踪OPToSOAPDomConv单元MethNode := BodyNode.AddChild(ExtMethName, SoapMethNS, (SoapMethNS <> '')); 显然SoapMethNS <>''为True...-----------------------没有掉用过java 的Webservice.纯推理推出来的。
 
谢谢各位了,用D7搞好了修改了以下地方InvRegistry.RegisterInvokeOptions(TypeInfo(PDADataExchangeWebService), ioDocument); RemClassRegistry.RegisterXSClass(ParamInfo, '', 'ParamInfo');//第二个参数改成了空 并且修改了vcl源码中的RegisterXSClass函数,修改成第二个参数为空时不再生成一个值。纯粹是根据用Delphi2010调用webservice接口时生成的头比较出来的。Delphi2010生成的格式如下:<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Body><MyRequestParameter10 xmlns="http://jssupervise.com/wsjdWeb/webService/PDADataExchangeWebService"><paramInfo xmlns=""><loginId>admin</loginId><password>8888</password><dataTime>2010-10-22</dataTime><data></data></paramInfo></MyRequestParameter10></SOAP-ENV:Body></SOAP-ENV:Envelope>D7生成的格式如下<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Body><MyRequestParameter10 xmlns="http://jssupervise.com/wsjdWeb/webService/PDADataExchangeWebService"><paramInfo><loginId>admin</loginId><password>8888</password><dataTime>2010-10-22</dataTime><data></data></paramInfo></MyRequestParameter10></SOAP-ENV:Body></SOAP-ENV:Envelope>修改了那几个地方以后D7就调用成功了。至于为什么这样修改和这样修改好不好还是不太清楚。
 
后退
顶部