Good WCF Client Design Template

My application communicates with a large number of wcf services, that is, my application has several assemblies, each of which uses a different wcf service.

I am looking for a good wcf client design template so that I can keep my code concise, multiple and elegant.

The wcf services I consume are the same - mostly used to check prices and then to book things.

+4
source share
1 answer

When you say that all services are the same, I assume that you mean that they are similar.

If they are really identical, you should be able to use the same WCF client for everyone (only with different addresses).

If this is not the case, you can define an interface that matches open functionality. It might look like this:

public interface IMyService { decimal GetPrice(int productId); void Book(int thingId); } 

Now write the IMyService implementations that serve as adapters between each WCF client and IMyService.

In the rest of the application, you only program against the IMyService interface. Optionally, you can use Injection Dependency to insert one or more specific IMyService implementations into the application code.

+3
source

Source: https://habr.com/ru/post/1302220/


All Articles