Home > Back-end >  Encountered in the Delphi Soap/web service using a strange question, please answer ~ ~ ~ ~ ~
Encountered in the Delphi Soap/web service using a strange question, please answer ~ ~ ~ ~ ~

Time:10-06

Use EncodeString/DecodeString transmission wav file, save the file to the local after the broadcast, in which meets a strange question:
Some wav files can complete saved to the local, and some are saved to a local file and the original wav files differ 1 KB, lead to can't play these files, do not know why this is, bother everybody to answer ~, thank you ~

The server interface implementation code is as follows:

 
{Invokable implementation File for TWavServer which implements IWavServer}

The unit WavServerImpl;

Interface

USES the Soap. InvokeRegistry System. The Types, Soap. XSBuiltIns, WavServerIntf,
System. The SysUtils, System. Classes, Vcl. Forms, Soap. EncdDecd;

Type

{TWavServer}
TWavServer=class (TInvokableClass IWavServer)
Public
The function GetWavList: string; Stdcall;
The function GetWavFile (const szfilename: string) : string; Stdcall;
end;

Implementation


{TWavServer}

The function TWavServer. GetWavFile (const szfilename: string) : string;
Var
Along TStringStream;
Ams: TMemoryStream;
The begin
If FileExists (ExtractFilePath (Application. ExeName) + 'Wav \' + szfilename) then
The begin
Ams:=TMemoryStream. Create;
Along=TStringStream. Create (");
Try
Ams. LoadFromFile (ExtractFilePath (Application. ExeName) + + szfilename 'Wav \');
Ams. SaveToStream (along);
Result:=EncodeString (along. DataString);
The finally
Ams. Free;
Along. Free;
end;
end;
end;

The function TWavServer. GetWavList: string;
Var
Sr: TSearchRec;
LST: TstringList;
The begin
LST:=TStringList. Create;
Try

If FindFirst (ExtractFilePath (Application. ExeName) + 'wav \' + '*. Wav', faAnyFile and not faDirectory, sr)=0 then
The begin
Try
Repeat
LST. Add (sr. Name);
Until (FindNext (sr) & lt;> 0);
The finally
FindClose (sr);
end;
end;
Result:=lst.Com maText;
The finally
LST. Free;
end;
end;

Initialization
{Invokable classes must be registered}
InvRegistry. RegisterInvokableClass (TWavServer);
End.


The client calling code is as follows:
 
The unit WavClients;

Interface

USES the
Winapi. Windows, Winapi Messages, System. SysUtils, System. Variants, System. Classes, Vcl. Graphics,
The Vcl. Controls, Vcl. Forms, Vcl. Dialogs, Soap. InvokeRegistry, Vcl. StdCtrls,
The Vcl. MPlayer, Soap. Rio, Soap. SOAPHTTPClient;

Type
TForm2=class (TForm)
HTTPRIO1: THTTPRIO;
Mp1: TMediaPlayer;
Btn1: TButton;
Btn2: TButton;
Lst1: TListBox;
Procedure btn1Click (Sender: TObject);
Procedure btn2Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;

Var
Form2: TForm2;

Implementation
USES the
WavServerIntf, Soap. EncdDecd;

{$R *. DFM}

Procedure TForm2. Btn1Click (Sender: TObject);
Var
Aintf: IWavServer;
The begin
Try
Aintf:=Self. HTTPRIO1 as IWavServer;
Lst1.Items.Com maText:=aintf. GetWavList;
The finally
Aintf:=nil;
end;
end;

Procedure TForm2. Btn2Click (Sender: TObject);
Var
Aintf: IWavServer;
Along TStringStream;
Ams: TMemoryStream;
BitStr: string;
The begin
Aintf:=Self. HTTPRIO1 as IWavServer;
Try
BitStr:=aintf GetWavFile (lst1. Items. Strings [lst1. ItemIndex]);
Along=TStringStream. Create (DecodeString (bitStr));
Ams:=TMemoryStream. Create;
Try
Ams. LoadFromStream (along);
Ams. SaveToFile (lst1. Items. Strings [lst1. ItemIndex]);
With mp1 do
The begin
The Close;
Mp1. FileName:=lst1. Items. Strings [lst1. ItemIndex];
The Open;
Play;
end;
The finally
Along. Free;
Ams. Free;
end;
The finally
Aintf:=nil;
end;
end;

End.


CodePudding user response:

Remove the encryption and decryption try?
  • Related