How to apply Task Async Pattern and WCF's ChannelFactory<TChannel>?
Asked Answered
B

2

13

We have a robust WCF client built in 2008 on .NET 3.5 (now recompiled under .NET 4.0) that talks to our own WCF service over the net.tcp binding. The robust client uses ChannelFactory<IOurServiceInterface>() to generate a service proxy, through which we currently make synchronous calls to the service. We get results back from each call; we have no one-way calls.

We are migrating to .NET 4.5 / C# 5 and would like to make the client asynchronous using async / await / TAP. How best to do this in a way that results in clean code, and good runtime performance?

(I've looked at MS documentation on this subject, but it always talks about running svcutil. We don't use svcutil; we use ChannelFactory directly. Also: MS documentation for calling operations asynchronously using a channel factory under .NET 4.5 are unchanged since .NET 3.0 days. Seems ChannelFactory hasn't embraced the new asynchrony.)

Berardo answered 18/11, 2012 at 18:11 Comment(0)
F
7

You can wrap existing APM (Begin*/End*) endpoints into TAP-ready Tasks using TaskFactory.FromAsync.

You may find my Async WCF Today and Tomorrow post helpful, which shows how to use TAP with the pre-VS2012 svcutil.

Flexible answered 18/11, 2012 at 18:28 Comment(1)
Thanks Stephen. After searching for info based on your answer, and after reading your post, I think that this is the best that can be done. I'm surprised that ChannelFactory in this day and age still expects you to use the APM pattern.Berardo
S
3

Did you see this ? I made an example of an awaitable [OperationContract] returning Task<TResponse>.

Sanction answered 29/11, 2012 at 0:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.