上一次通过soap,使IOS 访问了kbmmw服务器,今天顺便看能不能与android 共用服务器上的那个
下载图片的功能。首先说一下服务端的的程序,基本上就是前面的代码,没有变化,只是要indy 里面的
base64 编码功能,不再啰嗦,直接代码:
function Txalionsrv.Performgetimgm(ClientIdent: TkbmMWClientIdentity; const Args: array of Variant): Variant; var fs:TMemoryStream; filename:string; base64:pansichar; i:integer; flen,bsize:int64; b64:TIdencoderMIME; begin filename:='D:\picture\'+args[0]; if not FileExists(filename) then begin kbmMWRaiseServerException('文件不存在!'); exit; end; fs:=TMemoryStream.Create; b64:=TIdEncoderMIME.Create(); try fs.LoadFromFile(filename); result:=b64.EncodeStream(fs) finally fs.Free; b64.Free; end; end;
客户端为了显示图片,改变了一下界面
增加了一个Timage 控件,和一个显示按钮
把soap 调用整理成一个公共过程:
function remoterequest(ip,servicename,funcname:string;v:Variant;var StatusText:string;var vout:Variant):integer; var server:IProcessRequestSOAPPort; req:ProcessRequest; res:TkbmMWSOAPResponse; begin result:=-1; server:=GetIProcessRequestSOAPPort(false, 'http://'+ip+'/server1',nil); req:=ProcessRequest.Create; try // Setup request. req.ServiceName:=servicename;//'XALION_SRV'; req.ServiceVersion:=''; req.StateID:=-1; req.Func:=funcname;//'sumall'; // Setup identity. //req.Ident:=TkbmMWSOAPClientIdentity.Create; //req.Ident.Username:=’HANS’; //req.Ident.Password:=’somepassword’; req.Args:=v; // Call app server. res:=server.ProcessRequest(req); try // Check response. StatusText:=res.StatusText; if res.StatusCode=0 then // OK begin result:=0; vout:=res.Result; end; finally res.Free; end; finally req.Free; end; end;
然后在按钮点击里面使用下面代码:
procedure TForm1.Button2Click(Sender: TObject); var args:array[1..4] of Variant; ms:TMemoryStream; v,vout:variant; s:String; len,mlen:integer; b64:TIdDecoderMIME; img:Tbitmap; begin v:=VarArrayCreate([0,1],varVariant); v[0]:='1.JPG'; if remoterequest(servername.Text,'XALION_SRV', 'getimgm',v,s,vout)<>0 then begin edit1.Text:='bad' ; exit; end; Label1.Text:=s; s:=vout; b64:= TIdDecoderMIME.Create; try ms:=TMemoryStream.Create; b64.DecodeStream(s,ms); img:=Tbitmap.CreateFromStream(ms); image1.Bitmap:=img; finally ms.Free; b64.Free; end; end;
编译,然后在mac 上ios模拟器上运行,显示下面的效果:
整体感觉,ios 的模拟器比android 的速度快多了。
时间: 2024-09-30 21:40:31