简体   繁体   English

一个很好的WCF客户端设计模式

[英]A good WCF client design pattern

My application communicates with a large number of wcf services ie my application has several assemblies which each consume a different wcf service. 我的应用程序与大量的wcf服务通信,即我的应用程序有几个程序集,每个程序集使用不同的wcf服务。

I am looking for a good wcf client design pattern so that I can keep my code concise, reusuable and elegant. 我正在寻找一个良好的wcf客户端设计模式,以便我可以保持我的代码简洁,可重用和优雅。

The wcf services which I consume are all the same - the basically used to check prices and then book things. 我消费的wcf服务都是一样的 - 基本上用于检查价格然后预订。

When you say the all services are the same, I presume that you mean that they are similar . 当你说所有的服务都是一样的时候,我认为你的意思是他们是相似的

If they are truly identical , you should be able to use the same WCF client for all of them (just with different addresses). 如果它们完全相同 ,那么您应该能够为所有这些客户端使用相同的WCF客户端(仅使用不同的地址)。

If this is not the case, you can define an interface that conforms the exposed functionality. 如果不是这种情况,您可以定义符合公开功能的接口。 This might look like: 这可能看起来像:

public interface IMyService
{
    decimal GetPrice(int productId);

    void Book(int thingId);
}

Now write implementations of IMyService that serves as Adapters between each WCF client and IMyService. 现在编写IMyService的实现,作为每个WCF客户端和IMyService之间的适配器

In the rest of your application, you only program against the IMyService interface. 在应用程序的其余部分中,您只能针对IMyService接口进行编程。 Optionally, you can use Dependency Injection to inject either one or many concrete IMyService implementations into the application code. (可选)您可以使用依赖注入将一个或多个具体的IMyService实现注入到应用程序代码中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM