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;

posted @ 2012-10-28 10:43  delphi中间件  阅读(281)  评论(0编辑  收藏  举报