alnickels 0 Posted August 17, 2020 Does anybody know where I can find an example of a delphi client and server that will download binary files of size 250k or more using soap? Share this post Link to post
Sherlock 663 Posted August 17, 2020 Just let the server provide the client with a download link. Using soap to download data is quite cumbersome in my experience. Cumbersome meaning slow...and you might even need to convert binary data to a readable format like base64 server side and reconvert client side, costing more performance. Share this post Link to post
Alexander Elagin 143 Posted August 17, 2020 Convert the binary data to base64-encoded string and return it to the client which can decode it back to binary. In my experience, passing 2-5 megabytes this way does not cause any problems. Share this post Link to post
pcplayer99 11 Posted August 21, 2020 Hi, These codes I have tested ok. Server Side: unit TestAttachImpl; interface uses Soap.InvokeRegistry, System.Types, System.SysUtils, Soap.XSBuiltIns, TestAttachIntf; type { TTestAttach } TTestAttach = class(TInvokableClass, ITestAttach) public procedure GetAttach(var FileName: string; out Attach: TSOAPAttachment); stdcall; procedure PutAttach(const FileName: string; Attach: TSOAPAttachment); stdcall; end; implementation { TTestAttach } procedure TTestAttach.GetAttach(var FileName: string; out Attach: TSOAPAttachment); var Fn: string; begin //Send file to client Fn := 'F:\H264Output.mp4'; Attach := TSOAPAttachment.Create; Attach.SetSourceFile(Fn); FileName := ExtractFileName(Fn); end; procedure TTestAttach.PutAttach(const FileName: string; Attach: TSOAPAttachment); begin //receive file that client upload Attach.SaveToFile(ExtractFilePath(GetModuleName(0)) + FileName); end; initialization { Invokable classes must be registered } InvRegistry.RegisterInvokableClass(TTestAttach); end. Client-side: procedure TForm2.Button1Click(Sender: TObject); var Attach: TSOAPAttachment; Intf: ITestAttach; Path, Fn: string; begin //client download file Path := ExtractFilePath(Application.ExeName); Attach := TSOAPAttachment.Create; Intf := HTTPRIO1 as ITestAttach; try Intf.GetAttach(Fn, Attach); Attach.SaveToFile(Path + Fn); finally Intf := nil; Attach.Free; end; end; procedure TForm2.Button2Click(Sender: TObject); var Fn: string; Attach: TSOAPAttachment; Intf: ITestAttach; begin //client upload file if OpenDialog1.Execute then begin Fn := OpenDialog1.FileName; Attach := TSOAPAttachment.Create; Attach.SetSourceFile(Fn); Intf := HTTPRIO1 as ITestAttach; try Intf.PutAttach(ExtractFileName(Fn), Attach); finally Intf := nil; Attach.Free; end; end; end; Share this post Link to post
pcplayer99 11 Posted August 24, 2020 Hi, here is my demo project: https://github.com/pcplayer/WebServiceUploadFile Share this post Link to post