webservice Rest to receive an xml in Delphi

Asked

Viewed 514 times

3

Good afternoon.
A client wants to send me an . xml file
I created a Datasnap Rest Application project.
I have implemented the method as follows for JSON

function TFo_SM_Fornecedor.updateFornecedor(TObjJson: TJsonObject): TJsonValue;
Var
  Fornecedor: TFornecedor;
begin
  Fornecedor := TJson.JsonToObject<TFornecedor>(TObjJson.toJson);
  Try
    Result := TJSONString.Create('Incluindo Cliente..: ' +
      Fornecedor.tx_razaosocial);
  Finally
    FreeandNil(Fornecedor);
  End;    
end;

To receive a type Tjsonobject works perfectly.
But as I said at the beginning I will receive an . xml.
I have done several codes in Delphi to receive an xml and put the values in the base, but it is the first time I have to develop a server and I am without a direction.
Can one of your colleagues shed some light? At first ( a few days ago) I’m trying to change the parameter of the line

Function Tfo_sm_supplier.updateFornecedor(Tobjjson: Tjsonobject):

for something like

Function Tfo_sm_vendor.updateFornecedor(pArquivo_XML: Tstringtream):

But I am unsuccessful. If any of you can give me a light thank you.

1 answer

1

I don’t think you need to change the parameter, you could receive xml as a String without problems, just identify a specific json field...

I think of something sent to you as:

[
  {
    "xml": "todo xml aqui"
  }
]

Your function would receive a simple json and test if the key is "xml" treat as xml, if you don’t keep doing what you already do...

This I have implemented and works perfectly for various file formats and my API.

To send me an image I request that it be a String, or Base64, to send me an MP3 send me a String, the requester converts to TStringTream and send me the bytes in String.

On my side I only recognize the key.

  • Good morning @Júnior Moreira. Thank you for your attention :). Dude.. THE CLIENT WILL NOT CHANGE HIS . XML. That’s a fact. So I have to receive it the way it comes. His system sends an . XML file to an address. The only thing he can do on his side is CHANGE THE ADDRESS WHERE .XML. Do you understand me? That’s why I think I have to change the function parameter. If it is possible to skype, it would be of great help to me. : ) Or right here :) Hugs..

  • Ok, I will prepare a proper response since the client cannot change the request!

  • Good morning @Júnior Moreira. Thanks for your attention.. : ) I’m on hold.. I’m trying something here too. I hope to get somewhere. Hugs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.