How to send byte[] using WCF efficiently
I need to send byte[] array using WCF services and I care about message size and performance. My question is: Does WCF convert my binary data to Base64 stri开发者_运维技巧ng internally? (I use netTcpBinding) If it does, how to prevent it?
My contract looks almost as simple as
IMyService
{
byte[] GetData()
}
In terms of the actual XML, byte arrays are serialized as xs:base64Binary, which is a Base64 encoding (obviously).
However, when you specify the netTcpBinding, WCF uses a binary message encoding of that XML (BinaryMessageEncodingBindingElement) which will encode those bytes as a binary stream.
It's a bit of a convoluted process, but at the end of the day, if you're using any of the net*
bindings, byte arrays will go over the wire as raw bytes, not base64 strings. That's one of many reasons why it's generally more efficient to use the TCP or Named Pipe bindings, if you can.
精彩评论