Home Unit-test WCF contracts match for sync / async?
Reply: 0

Unit-test WCF contracts match for sync / async?

user7585
1#
user7585 Published in September 20, 2018, 10:21 pm

WCF makes it easy to call services synchronously or asynchronously, regardless of how the service is implemented. To accommodate clients using ChannelFactory, services can even define separate sync/async contract interfaces. For example:

public interface IFooService
{
    int Bar();
}

[ServiceContract(Name = "IFooService")]
public interface IAsyncFooService
{
    Task<int> BarAsync();
}

This allows the client to reference either contract version, and WCF translates the actual API calls automatically.

One drawback to providing both contract versions is that they must be kept in-sync. If you forget to update one, the client may receive a contract mismatch exception at runtime.

Is there an easy way to unit test the interfaces to ensure they match from a WCF metadata perspective?

share|improve this question
  • 5
    Alternatively, it may be easiest to use T4 templates to generate the async contract rather than manually maintain both. – Scott Wegner Jan 2 '14 at 17:53
  • 1
    You can try to use Message as a Request and Response DTO, so your ServiceContract will be the same forever. Here's an example – GSerjo Jan 3 '14 at 1:39
  • @GSerjo: That's a useful design choice which could avoid the need to evolve our APIs. Ours do not follow such a pattern though. – Scott Wegner Jan 3 '14 at 16:07

2 Answers 2

active oldest votes
up vote 8 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.335727 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO