Hello Experts,
Please can i use datacontracts in WCF for streaming instead of message Contract.
If yes, will it offer any performance improvement?
THanks
Hello Experts,
Please can i use datacontracts in WCF for streaming instead of message Contract.
If yes, will it offer any performance improvement?
THanks
Yes, you can... it is recommended if large amount of data to be transfered or streamed.
Check this http://blog.thekieners.com/2010/05/04/optimize-data-contracts-for-better-wcf-performance/
Answer depends on binding you use. For TCP or Named pipe transport protocols you can stream any data - including data contracts. If you want to use streaming over HTTP (supported by BasicHttpBinding) you have to some several constraints:
Only valid operation definitions for streaming over HTTP are:
// StreamedResponse
[OperationContract]
Stream GetData(int id);
// StreamedRequest
[OperationContract]
int PostData(Stream data);
// Streamed
[OperationContract]
Stream WorkWithData(Stream data);
[OperationContract]
DoSomethingResponse DoSomething(DoSomethingReqest request);
[MessageContract]
public class DoSomethingRequest
{
// Custom data and data contract allowed only as SOAP headers which are always buffered
[MessageHeader]
public MyDataContract CustomHeader { get; set; }
// No other member allowed
[MessageBodyMember]
public Stream Data { get; set; }
}
[MessageContract]
public class DoSomethingResponse
{ ... }
If you don't follow these constraints you will end up with two cases: