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 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.
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? If it's real code:
byte[]
.return doc;
as the last line, why have GenerateDoc()
inside GetDoc()
? GetDoc()
doesn't really provide any true benefit.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