delphi如何调用WebService接口啊(等待救命...........)(80分)

  • 主题发起人 主题发起人 jack011
  • 开始时间 开始时间
J

jack011

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大虾:

听说SOAPHTTPClient控件可以实现,可是不知道咋用啊?
马上要交货啊!
 
对,没错,就是SOAPHTTPClient。
你把webservice的WSDL导入就行的。
 
to jennykiller:
帮我看看:

var
//MyWS: AttributeTestSoap; //这个就是WSDL下的类接口对象
MyWS:AlertServiceSoap;
msg: widestring;
bb: double;
begin
//HTTPRIO2 其实就是所谓的代理类,它负责进行数据传输发送Request和接受Response的
MyWS := HTTPRIO1 as AlertServiceSoap;
try
MyWS.report('13723404959', 'delphi测试短信成功!');
//Response.Write(&quot;<script>alert('信息已经发送!')</script>&quot;);
Memo.Lines.Add('短信发送成功');
except
Memo.Lines.Add('短信发送失败');
end;

end;

编译通过,但是执行错误啊:
Access violation at address OOE36F95 write of address OOE36F95
 
源码如下,另外引用了一个RSer单元,其中定义了接口,其他引用单元可以不考虑

unit ULogin;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,StrUtils,
Dialogs, StdCtrls, Buttons, ExtCtrls, Rio, SOAPHTTPClient, Animate,
GIFCtrl, ComCtrls, WinSkinForm, ComObj;


//调用WebService时使用线程.
type
TShowAnim = class(TThread)
private
procedure DoAnimate;
{ Private declarations }
protected
procedure Execute; override;
destructor Destroy; override;
end;
type
TCallWebService = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
destructor Destroy; override;
end;


type
TfrmLogin = class(TForm)
Panel1: TPanel;
edUser: TLabeledEdit;
edPass: TLabeledEdit;
btOK: TBitBtn;
btExit: TBitBtn;
Bevel1: TBevel;
RxGIFAnimator1: TRxGIFAnimator;
Label1: TLabel;
ProgressBar1: TProgressBar;
Animate1: TAnimate;
WinSkinForm1: TWinSkinForm;
procedure btOKClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
FTryLoginCount : integer; //尝试登录次数
procedure Animate;
procedure DoCallWeb;
{ Private declarations }
public
//输出变量:用户ID,用户口令,学籍号,所学课程
O_ID,O_Pass,O_StudentID,O_date,O_Course : string;
//是否登录成功。
O_ISLogined : Boolean;
{ Public declarations }
end;

var
frmLogin: TfrmLogin;
thrShowAmin : TShowAnim; //调用TShowAnim线程变量
thrCallWebservice : TCallWebService; //调用WebService线程变量
V_Return : string;
CS1,CS2:TRTLCRITICALSECTION;//定义临界变量

implementation

uses RSer, PublicUt, UDm, UMain;

{$R *.dfm}

procedure TfrmLogin.btOKClick(Sender: TObject);
begin
//临时指定登录名及所能学习的课程 Add by Gongqin
GStudentID := '1001001320030328000100';
GCourse := '100001,100002,100003,100004,100005,100006,100007';
//***********************************************

frmLogin.ModalResult := mrOk;
{Inc(FTryLoginCount);
thrShowAmin:= TShowAnim.Create(False); //显示动画,临时注释}
end;

procedure TfrmLogin.FormCreate(Sender: TObject);
begin
InitializeCriticalSection(CS1); //
InitializeCriticalSection(CS2); //
//登录次数初始化
FTryLoginCount :=0;
end;

{ TCallWebService }

procedure TfrmLogin.Animate;
var
i : integer;
begin
enterCriticalSection(cs1);
//frmLogin.RxGIFAnimator1.Animate := True;
Animate1.Active := True;
thrCallWebservice:= TCallWebService.Create(False);
{ for i := 0 to 12000000 do
begin
ProgressBar1.StepBy(20);
end;}
leaveCriticalSection(cs1);
end;

procedure TfrmLogin.DoCallWeb;
var P_Interface : REducationSoap; //WebService提供的接口变量
//向服务器端提交的用户ID号, 用户登录口令
V_ID,V_Pass: string;
begin
//EnterCriticalSection(cs2);
V_ID := frmLogin.edUser.Text;
V_Pass := frmLogin.edPass.Text;
P_Interface := Dm.SOAP as REducationSoap;
// thrShowAmin := TShowAnim.Create(False);

V_Return :=P_Interface.CheckUser(V_ID,V_Pass);
//LeaveCriticalSection(cs2);
{ for i := 0 to 100000000 do
begin
Application.ProcessMessages;
end;}
end;

procedure TShowAnim.DoAnimate;
begin
frmLogin.Animate;
end;

procedure TShowAnim.Execute;
begin
try
Priority :=tpIdle;
Synchronize(doAnimate);
except
Msg('网络服务请求失败!','提示',0,0);
end;
end;

destructor TCallWebService.Destroy;
var
//返回字串,返回学员的学籍号、用户所可学习的课程ID。
V_Field : string;
V_LoginOK : Boolean; //是否验证成功

begin
frmLogin.Animate1.Active := false;
frmLogin.ProgressBar1.visible :=False;

begin
getInfo(V_Return, V_Field,'[Field]');

if V_Field ='True' then
begin
V_LoginOK := True;

//如果登录成功则为全局变量赋值 Add by Gongqin
getInfo(V_Return, V_Field,'[Field]');
GStudentID := V_Fie
 
to hebei_ty:

谢谢,兄弟!
我估计SOAPHTTPClient哪个地方设置错了,或则是我在WSDL导入时出错了!

不然调用:
MyWS.report('13723404959', 'delphi测试短信成功!');就报错了!
哪位兄弟知道?
谢谢各位!
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部