在delphi中调用webservice

Filed under: 程序开发 | 1 Comment »
Posted on

最近的一个项目需要用到这个技术,于是做了一个demo来验证可行性

webservice是用c#写的,提供三个操作:UserLevel 、UserDate、IsLogin

在delphi中使用webservice导入,以下为主程序:

  1. procedure TForm1.Btn_OkClick(Sender: TObject);
  2. var
  3.   strWSDL:string;
  4.   Iservice:Service1Soap;
  5.   msg:widestring;
  6.   strUsername:string;
  7.   strPassword:string;
  8.   IsLogin:boolean;
  9.   UserLevel:integer;
  10.   UserDate:string;
  11. begin
  12.   strWSDL:= Edit1.Text;
  13.   HTTPRIO1.WSDLLocation:=strWSDL;
  14.   strUsername:=EdtUserName.Text;
  15.   strPassword:=EdtPassword.Text;
  16.   //HTTPRIO1.HTTPWebNode.Agent := 'Borland SOAP 1.2';
  17.   //HTTPRIO1.HTTPWebNode.UseUTF8InHeader := true;
  18.   Iservice:= HTTPRIO1 as Service1Soap;
  19.   IsLogin:= Iservice.IsLogin(strUsername,strPassword);
  20.   if IsLogin=true then
  21.   begin
  22.   UserLevel:= Iservice.UserLevel(strUsername,strPassword);
  23.   UserDate:=  Iservice.UserDate(strUsername,strPassword);
  24.   msg:='登陆成功,到期时间为'+UserDate;
  25.   if UserLevel=2 then
  26.   begin
  27.     msg:=msg+'付费用户';
  28.     Edt_1.ReadOnly:=false;
  29.     Edt_2.ReadOnly:=false;
  30.     end
  31.   else
  32.   begin
  33.   msg:=msg+'免费用户';
  34.     Edt_1.ReadOnly:=true;
  35.     Edt_2.ReadOnly:=false;
  36.   end
  37.  
  38.   end
  39.   else
  40.   msg:='登陆失败,用户名或者密码错误';
  41.   LblMsg.Caption:=msg;
  42. end;

相关文章