Is it a good practice to return a byte[] in a WCF service which will be invoked by many applications
below is the code
public byte[] GetDoc(string docParam)
{
byte[] doc;
doc = GenerateDoc(docParam);
}
Thanks
Is it a good practice to return a byte[] in a WCF service which will be invoked by many applications
below is the code
public byte[] GetDoc(string docParam)
{
byte[] doc;
doc = GenerateDoc(docParam);
}
Thanks
It's used when you want to transfer a binary buffer, and also perform Large Data Transfer using MTOM encoding (set on the Binding configuration). How to perform Large Data Transfer found here.
It's good practice to factor common code into a convenient method so that many callers could call this convenient method. This is regardless of return type. If the callers would need to manipulate the byte[], then this can become convenient and eliminate redundant code. By the way, regarding the code that you posted, is that real code or just an example. Because if it's real code, (i) first it won't compile, because it doesn't a byte[]; (ii) if call return doc as the last line, why have GenerateDoc() inside GetDoc and GetDoc doesn't really provide any true benefit?
It's definitely possible to return byte[]
and WCF allows you to do this using MTOM encoding.
If the size of the binary buffer is big you could use WCF streaming. In this case you would return Stream
data type, and read from that Stream
on the client side.