delphi webservices传文件


webservices传文件

有两种方法,一种是把二进制对象转成base64码,返回字符串,应该是最简单的方法,另外一种就是返回二进制数组TByteArray
服务器:
function TFileSoap.getPic(out size:integer): TByteArray;
var
buf:TMemoryStream;
begin
try
 if not FileExists('c:\1.bmp') then
 raise Exception.Create('file not found.');

 buf:=TMemoryStream.create;
 buf.LoadFromFile('c:\1.bmp');
 size:=buf.Size;
 setlength(result,size);
 move(buf.Memory^,result[0],size);
finally
 buf.free;
end;
end;
客户端
procedure TForm1.Button1Click(Sender: TObject);
var
size:integer;
buf:TMemoryStream;
ary:TByteArray;
begin
buf:=TMemoryStream.create;
try
 ary:=GetIFileSoap.getPic(size);
 buf.SetSize(size);
 move(ary[0],buf.memory^,size);
 Image1.Picture.Bitmap.LoadFromStream(buf);
finally
 buf.free;
end;
end;

联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678