用DELPHI7建WEB SERVICE时,服务器端编译成功,但客户端调用出错
问题:
在服务端如果设置返回给客户端的值为定量时,客户端能够正确调用,但是如果服务端要通过查询数据库
时,客户端就会报错:Access violation at Address 019B8C6C in module "XXWEBSERVICE.dll".Read of Address 000000AC.
下面是服务器端WEB MODULE的源代码:
- Delphi(Pascal) code
{ SOAP WebModule }unit uWebModule;interfaceuses SysUtils, Classes, HTTPApp, WSDLPub, SOAPPasInv, SOAPHTTPPasInv, SOAPHTTPDisp, WebBrokerSOAP, DB, DBClient, MConnect, SConnect, ObjBrkr, InvokeRegistry, WSDLIntf, TypInfo, WebServExp, WSDLBind, XMLSchema, ADODB, DBTables;type TWebModule1 = class(TWebModule) HTTPSoapDispatcher1: THTTPSoapDispatcher; HTTPSoapPascalInvoker1: THTTPSoapPascalInvoker; WSDLHTMLPublish1: TWSDLHTMLPublish; ADOQuery1: TADOQuery; ADOStoredProc1: TADOStoredProc; private { Private declarations } public { Public declarations } end;var WebModule1: TWebModule1;implementation{$R *.dfm}uses WebReq,DataType,ServicesInterface;typeTInfo=class(TInvokableClass,IsfcInfo)ProtectedFunction ApproveTestStart(dutSN,OpeID,LineName:string):TsfcInfo;StdCall;End; //定义这个接口类procedure createinfo(out obj:tobject);//此过程为创建类实例,必须手工添加beginobj:=TInfo.Create;//创建类实例end;Function TInfo.ApproveTestStart(dutSN,OpeID,LineName:string):TsfcInfo;StdCall;Begin Result:=TsfcInfo.Create; try with WebModule1.ADOQuery1 do Begin close;//[color=#FF0000]测试时发现到这部分就出错了[/color] sql.Text:='select emp_name from sajet.sys_emp where rownum=1'; open; IF NOT ISEMPTY THEN result.Approved:=fieldbyname('emp_name').AsString; End; finally End;End;initializationWebRequestHandler.WebModuleClass:=TWebModule1;InvRegistry.RegisterInvokableClass(TInfo,createinfo);end.下面是客户端调用的代码:
- Delphi(Pascal) code
uses IsfcInfo1;procedure TForm1.Button1Click(Sender: TObject);var test:TsfcInfo;//定义对象begin test:=TsfcInfo.Create; test:=(Httprio1 as IsfcInfo).ApproveTestStart(edit1.Text,'',''); showmessage(test.Approved);//调用方法end;
请各位朋友帮忙,看怎样才能解决查询数据库报错的问题。
[解决办法]