delphi中调用webservice时,出错,请大虾帮忙~~~

csudjf 2011-09-05 03:42:37
--这是我写的函数
function Tfrm_login.InitADAuth: string;
var
furls: string;
Iservice : ADAuthSoap;
begin
//取WS地址
QueryOpen(tempquery1,'select top 1 * from pln_message where class_id = ''ADAuth'' and remark = ''ccc'' ');
if not tempquery1.Isempty then
begin
//验证
Iservice := GetADAuthSoap(true,'http://svn.ccin.com/MOAWebService/ADAuth.asmx?WSDL');
result := Iservice.ADAuthByFlag(UserName,password,tempquery1.Fieldbyname('mes_name').asstring);
end
else
begin
result := 'false';
Iservice.free;
end;
end;

调用如下webservice

// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://svn.ccin.com/MOAWebService/ADAuth.asmx?wsdl
// Encoding : utf-8
// Version : 1.0
// (2011-9-4 13:43:12 - $Revision: 1.9.1.0.1.0.1.9 $)
// ************************************************************************ //

unit ADAuth;

interface

uses InvokeRegistry, 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"


// ************************************************************************ //
// Namespace : http://tempuri.org/
// soapAction: http://tempuri.org/%operationName%
// transport : http://schemas.xmlsoap.org/soap/http
// binding : ADAuthSoap
// service : ADAuth
// port : ADAuthSoap
// URL : http://svn.ccin.com/MOAWebService/ADAuth.asmx
// ************************************************************************ //
ADAuthSoap = interface(IInvokable)
['{56D59372-0D3E-E8B9-1A41-10407C99CD92}']
function IsAuthPass(const strUserName: String; const strPassword: String): String; stdcall;
function ADAuthByFlag(const name: String; const pwd: String; const flag: String): String; stdcall;
end;

function GetADAuthSoap(UseWSDL: Boolean=System.False; Addr: string=''): ADAuthSoap;


implementation
uses SOAPHTTPClient;

function GetADAuthSoap(UseWSDL: Boolean; Addr: string): ADAuthSoap;
const
defWSDL = 'http://svn.ccin.com/MOAWebService/ADAuth.asmx?wsdl';
defURL = 'http://svn.ccin.com/MOAWebService/ADAuth.asmx';
defSvc = 'ADAuth';
defPrt = 'ADAuthSoap';
var
RIO: THTTPRIO;
begin
Result := nil;
if (Addr = '') then
begin
if UseWSDL then
Addr := defWSDL
else
Addr := defURL;
end;
RIO := THTTPRIO.Create(nil);
try
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
end else
RIO.URL := Addr;
Result := (RIO as ADAuthSoap);
finally
if Result = nil then
RIO.Free;
end;
end;


initialization
InvRegistry.RegisterInterface(TypeInfo(ADAuthSoap), 'http://tempuri.org/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ADAuthSoap), 'http://tempuri.org/%operationName%');
InvRegistry.RegisterInvokeOptions(TypeInfo(ADAuthSoap), ioDocument);

end.



出现奇怪的问题,按F9进行代码跟踪时,可以从服务器取数据,但直接运行exe文件时,报地址错误
---------------------------
[DEBUG]
---------------------------
Access violation at address 07992334. Write of address 07992334
---------------------------
确定
---------------------------


这是怎么回事啊~~

...全文
93 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
csudjf 2011-09-05
  • 打赏
  • 举报
回复
谁帮我下啊,一天都在搞这两句代码,崩溃啊,我可以加分的,一句话
csudjf 2011-09-05
  • 打赏
  • 举报
回复
谁帮忙提点意见,不是delphi环境有问题
csudjf 2011-09-05
  • 打赏
  • 举报
回复
嗯,我在胡乱试,有点抓狂
林石公 2011-09-05
  • 打赏
  • 举报
回复
至少这句:

Iservice.free;

是没用的,可以注释掉

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧