Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning a byte[] in WCF service

Tags:

wcf

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

like image 210
acadia Avatar asked May 21 '10 19:05

acadia


2 Answers

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.

like image 101
Gart Avatar answered Nov 15 '22 05:11

Gart


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:

  1. It won't compile, because it doesn't return a byte[].
  2. If you were to call return doc; as the last line, why have GenerateDoc() inside GetDoc()? GetDoc() doesn't really provide any true benefit.
like image 33
Kevin Le - Khnle Avatar answered Nov 15 '22 05:11

Kevin Le - Khnle