Is Rx under 3.5SP1 forward-compatible with Rx and TPL under 4.0?
I want to begin enabling our C# .NET 3.5SP1 project's code with asynchrony. My primary use case is to invoke WCF services asynchronously.
Our WCF service layer is entirely interface-based, but those interface method signatures imply that the implementations are assumed to execute synchronously (e.g. SomeDataContract GetSomeDataContractByID(SomeID id);
. I'd like to avoid retrofitting the plethora of interfaces to support asynchronous execution with the .NET framework asynchronous pattern of IAsyncResult
and Beg开发者_如何学GoinOperation
/EndOperation
. I want a more manageable way to do this.
We use T4 templates to generate a lot of code, so I'd like to be able to generate an asynchronous version of the interface based on the synchronous one. An implementation of the asynchronous interface would invoke the WCF service asynchronously, ideally using .NET 4.0's TPL's Task<T>
to represent the operation as a task and returning that to the caller. The problem is .NET 3.5SP1 has no such TPL and hence no nice Task<T>
.
What are my options here, keeping in mind compatibility between .NET 3.5SP1 and .NET 4.0? I'm open to dropping the Task<T>
(if I misunderstand its purpose) in favor of something else that's cross-compatible between the two frameworks, like maybe Rx?
Rx's API is (nearly) identical on 3.5 vs 4.0 (the difference being an extra IScheduler that queues Tasks). Rx is a great choice here, because it will easily let you stub WCF service calls in a realistic way:
return Observable.Return(stubObject).Delay(TimeSpan.FromMilliseconds(750));
精彩评论