xdata service returning image

Hi, I created a simple example service returning an image (WMF).
this is the code on the server side :

// interface
 [HttpGet]
    function GetAlphaFile : TMetafile;


// implementation
function TMyService.GetAlphaFile: TMetafile;


begin
 TXDataOperationContext.Current.Response.Headers.SetValue('content-type', 'image/wmf');
 LoadAlphaCamPreviewIntoMetaFile('C:\NW1835\Truciolare\1835_1.ard',result);
end;

// client side

procedure TClientMainForm.btnGetAlphaGeoPreviewClick(Sender: TObject);
var
  c: TXDataClient;
  MyService: IMyService;
begin
  // istanzia un oggetto
  c := TXDataClient.Create;
  try
    // imposta uri del server
    c.URI := URI;



    // Retrieve data
      MyService := c.Service<IMyService>;

    var
      r: TMetafile := MyService.GetAlphaFile;

      Image1.Picture.Metafile.Assign(r);
      r.Free;
    //ShowMessage(Format('La somma %s + %s = %f', [edA.Text, edB.Text, r]))

  finally
    c.Free
  end;
end;

I get an error : Json Converter not found.

Where do I have to correct?

You should return a TStream instead of TMetafile and provide the image content in the returned stream.

Thanks for your help.
Now my app works well: the client asks the server for an image and this returns the data correctly. But there is a curious behaviour. The picture received is scaled correctly if the client is connected to the local server. With the remote server, the image control doesn't scale correctly.
I don't know why this is. The code is the same.

Is this from the browser? Inspect the network request executed by the browser in both situations and check if the response is exactly the same (at least same content length, etc.) Maybe the metafile you are providing is different?

Other than this, if everything is 100% sure to be the same, it's something at your client side.

I use Xdataclient in a VCL application. The server app on my PC and remote PC is the same. The WMF files are those I uploaded from my PC.

Setting the Timage autosize property to true, the Timage control changes its bounds accordingly with the size of geometry and shows completely the figure
(localhost). When I go on online the image is truncated. So the data sent from the data server online are incomplete. I don't know why.

I saved both images (online and localhost). The size is the same. If I open both files with a hexadecimal editor the content is different.

I understood where is the problem.
Since I extract the image from a container file and call some Windows routines that concern the metafiles and since these are two different versions of Windows, on the online PC (Windows 2022 server) the result is not as expected (the file is corrupt).

If you're interested, here's a blog post that goes into a lot more detail about image handling in general.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.