We try to make one single web service that can output json, xml as well as pdf and xlsx.
The system flow works now for a text output (json, xml) or binary (pdf, xlsx) but not for both, because we assigning the 'Response Body’ property can be assigned to only one process flow variable.
So what we need is a possibility to respond with a string or a binary body.
Would that be possible? Or is there a work around?
Have you tried converting your text responses to varbinary and using a varbinary process variable for both? It's hard to be certain if this would give the desired result without trying it, but it's worth a shot. If not, then this is currently impossible and would require some changes in Indicium, for which you can create a ticket or an Idea.
Please note that when converting text to varbinary, you need to take encoding into consideration. Your best bet is to use a UTF-8 encoding, which will probably require you to collate your text to a UTF-8 collation before converting.
Have you tried converting your text responses to varbinary and using a varbinary process variable for both? It's hard to be certain if this would give the desired result without trying it, but it's worth a shot. If not, then this is currently impossible and would require some changes in Indicium, for which you can create a ticket or an Idea.
Please note that when converting text to varbinary, you need to take encoding into consideration. Your best bet is to use a UTF-8 encoding, which will probably require you to collate your text to a UTF-8 collation before converting.
SET @response_body = CAST(@response_body_text COLLATE Latin1_General_100_CI_AS_SC_UTF8 AS VARBINARY(MAX));
The result in Postman looks almost good, see below. Do you think the NULL characters can be eliminated with some additional settings in the response header?
I think this problem occurs because @response_body_test is of the type nvarchar which uses two bytes per character, which isn't changed by the collate instruction. When converting to varbinary, the extra byte turns into a null byte (00).
You should be able to avoid this by converting to varchar first:
This seems like a lossy operation, but it shouldn't be due to the COLLATE Latin1_General_100_CI_AS_SC_UTF8 instruction.
As for the idea you mentioned, something like that would work, but it shouldn't even be necessary. Indicium is able to do this right autonomously. It doesn't right now, but it could do without any changes to the model. I have made note of this already as something to pick up soon. If you want to be able to track a ticket for this, then you can report one.
In the process flow text outputs (json, xml, csv, etc..) are now prepared and saved in a varchar(max) variable. In the last step the text variable is converted to a varbinary with this:
SET @response_body = CAST(@response_body_text COLLATE Latin1_General_100_CI_AS_SC_UTF8 AS VARBINARY(MAX));
The varbinary variable is linked to the Response Body property.
So thank you for the tips and if you see possibilities for further optimization in Indicium I would do that. With this we can make very generic API’s for multipurpose use.
I wrote that Indicium would be able to handle this properly autonomously but that's not true, I was thinking of something else. I think the best solution to make a use case like yours easier to implement is indeed the idea that you suggested. Can you create an Idea for this here on the Community?
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.