I have a web service that returns the binary array of an object. Is there an easier way to transfer this with SOAP or does it need to be contained in XML? It's working, but I had to increase the send and receive buffer to a large value. How much is too much?
Transferring binary in XML as an array seems really inefficient, but I can't see any way to add a binary attachment using .NET.
soap is an xml-based protocol, which means that all data inside the soap envelope must be text-based. if you want to include binary data in a soap message, it too must be text-based. to achieve this, you can convert binary data to a base64 encoded string and simply embed the string inside the soap message.
A SOAP message MUST use the SOAP Envelope namespace. A SOAP message must NOT contain a DTD reference. A SOAP message must NOT contain XML Processing Instructions.
SOAP uses XML to package the data passed to a method, or received as a response. SOAP itself is nothing more than a set of rules that define how to describe method calls and return values using XML syntax. XML merely describes data, without consideration for the way that the data is processed or presented.
As an array? Do you mean that you are sending
<byte>8</byte>
<byte>127</byte>
etc? If so then you can certainly improve on it by converting the byte array into a hex string beforehand, eg.
<codedArray>087F09AFBD.....</codedArray>
This is the most common approach for sending images, etc, via SOAP. However, even then you are correct to question it. You should really be looking at other, more RESTful transfer protocols, IMHO.
In the HTTP protocol, you are sending one message of mime type text/xml which contains the SOAP message. But the HTTP protocol allows you to send multiple messages, like an Email composed by the message and the attachments. That's called "Soap with Attachments" http://en.wikipedia.org/wiki/SOAP_with_Attachments It's done with a mime type "multipart/related".
Check that about how to do with WCF http://msdn.microsoft.com/en-us/library/ms733742.aspx
Well really you shouldn't be sending binary information with a webservice. Doing so sort of invalidates the point of using a webservice, compatibility. Ideally you would serialize your object as xml. However if you're sending information which is inherently binary, say an image, then you can for sure put that in the payload of your SOAP message. How much information is really a function of how long you wish to wait and how fast your network is. I don't believe there is any actual limit on the size of the information you can send. If it is truly a lot (50 meg+ seems like an arbitrarily large number) then you might wish to consider alternative transport protocols like streaming it over a socket.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With