You are not logged in.
I can run a server function from a client station if I used TSQLRestServerDB TSQLite3HttpClient server side and client-side
I need to send me an xml file from the server (I read files from a directory server)
thanks corchi
Offline
I only found this documentation,
http://synopse.info/forum/viewtopic.php?id=256
where I can entice the right one?
thanks corchi
Offline
In the official documentation, to be downloaded from http://synopse.info/files/synproject/sampledoc.zip
See http://synopse.info/forum/viewtopic.php?id=55
In the SAD document, there is a whole chapter about Service programming.
See also http://synopse.info/forum/viewtopic.php?pid=233 (less complete)
Offline
ok thanks,
I have read and produced the following example that sends a filename to the server which returns the string read xml file in the directory server:
unit FileTables
....
function TServiceServer.DataAsXML(aRecord: TSQLRecord;
aParameters: PUTF8Char; const aSentData: RawUTF8; out aResp, aHead: RawUTF8): Integer;
var //aData: TSQLRawBlob;
sfilename:RawUTF8;
XmlDoc: TNativeXml;
aData: RawUTF8 ;
begin
writeln('Start DataAsXML');
if not UrlDecodeNeedParameters(aParameters,'FILENAME') then begin
result := 404; // invalid Request
writeln('invalid Request');
exit;
end;
while aParameters<>nil do begin
UrlDecodeValue (aParameters,'FILENAME=',sfilename,@aParameters);
end;
writeln(format('filename: %s',[sfilename]));
if FileExists(sfilename) then
begin
writeln(format('Exist file: %s',[sfilename]));
try
XmlDoc := TNativeXml.Create(nil);
XmlDoc.LoadFromFile(sfilename);
if (XmlDoc <> nil) Then
begin
aData := XmlDoc.WriteToLocalString;
end;
finally
XmlDoc.Free;
end;
end
else
begin
result := 404; // invalid Request
exit; // we need a valid record and its ID
end;
aResp := JSONEncodeResult([aData]);
//aResp := JSONEncodeResult([SynCommons.BinToHex(aData)]);
// idem: aResp := JSONEncode(['result',BinToHex(aRecord.fData)],TempMemoryStream);
result := 200; // success
end;
..............................end FileTables
........ Client procedure
Var
sfilename:String;
XmlDoc: TNativeXml;
aData: RawUTF8;
begin
..
aData := ADatabaseServer.CallBackGetResult('DataAsXML',['filename',StringtoUTF8(sfilename)]);
if Length(aData)>0 then
begin
sfilename := nome;
sfilename := format('%s%s.xml',[GetTempDir, ReplaceStr(sfilename,'\','_')]) ;
XmlDoc.ReadFromString(UTF8ToString(aData));
XmlDoc.SaveToFile(sfilename);
end;
...
end;
but now I want to send the xml string to the server and the server would that save the document with a specific name
I wrote the following example using "CallBackPut" but I can not send the parameters type "filename" to "XMLAsData",
and I can not read the parameters returned by procedure "aResp: JSONEncodeResult = ([sFileName]);"
unit FileTables
....
function TServiceServer.XMLAsData(aRecord: TSQLRecord;
aParameters: PUTF8Char; const aSentData: RawUTF8; out aResp, aHead: RawUTF8): Integer;
var //aData: TSQLRawBlob;
sfilename:RawUTF8;
XmlDoc: TNativeXml;
aData: RawUTF8 ;
Node: TXmlNode;
begin
writeln('Start XMLAsData');
// if not UrlDecodeNeedParameters(aParameters,'FILENAME') then begin
// result := 404; // invalid Request
// writeln('invalid Request');
// exit;
// end;
// while aParameters<>nil do begin
// UrlDecodeValue (aParameters,'FILENAME=',sfilename,@aParameters);
// end;
// writeln(format('filename: %s',[sfilename]));
if length(aSentData)>0 then
begin
// writeln(format('Exist data: %s',[aSentData]));
try
XmlDoc := TNativeXml.Create(nil);
XmlDoc.ReadFromString(UTF8ToString(aSentData));
sfilename := format('%s%s.xml',[GetTempDir, ReplaceStr(sfilename,'\','_')]) ;
XmlDoc.SaveToFile(sfilename);
finally
XmlDoc.Free;
end;
end
else
begin
result := 404; // invalid Request
exit; // we need a valid record and its ID
end;
aResp := JSONEncodeResult([sfilename]);
writeln(format('Exist data: %s',[aResp]));
// idem: aResp := JSONEncode(['result',BinToHex(aRecord.fData)],TempMemoryStream);
result := 200; // success
end;
..............................end FileTables
........ Client procedure
Var
sfilename:String;
XmlDoc: TNativeXml;
aData: RawUTF8;
aResponse: RawUTF8;
begin
...
aData := " Here insert the xml string !!!!!!!!"
ADatabaseServer.CallBackPut('XMLAsData',aData,aResponse);
sfilename := UTF8ToString(aResponse); "the value returned is always empty !!!!!!!!"
..
end;
can you help me ?
thanks corchi
Offline