I'm constructing a REST service accepting Foo objects containing a mix of String and binary data. This is the XML I got so far.

<foo>
     <text>regular text</text>
     <text mime="application/octet-stream">base64 encododed binary data</text>
</foo>

Is this a good idea or are there drawbacks inlining large amounts (MBs) of binary data?

As a minor design detail, I'm trying to settle between using <text mime=".."/> or a dedicated name <binary>...</binary> for the binary data. Which would be more coherent?

有帮助吗?

解决方案

I would recommend including in your request/response xml's only the location where you will store the binary data you want to pass and then retrieve that data executing another request. The cons of that solution would be to execute another request but the pros are on your side:

  • no need to serialize/deserialize your 64 strings
  • easier testing of your rest ws
  • less bloated xml

其他提示

HTTP is designed to transmit payloads of arbitrary length. Sending MBs of data will be fine. Transmitting the data by base64 encoding is not advised because it will increase the number of bytes that you must send over the wire, degrading throughput.

I would suggest instead that you consider a multipart mime type rather than XML.

what's your webservice container? the format of xml would be generated by your binary serializer. axis2 may be good for you. it's based on axiom, offering direct binary support

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top