本文介绍了在静态类封装WCF代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计的web服务,这将根据给定的对象的属性调用不同的外部网络服务(一个请求,例如)。 ISomeInterface>将参照这些Web服务是通过在Visual Studio 2008中的添加Web引用菜单,正如你知道的,创建一个代理类为每个端点继承自 System.ServiceModel.ChannelBase&LT添加;。(其中 ISomeInterface 是由特定服务的WSDL定义端点)

I am designing a web service which will call different external web services according to the properties of a given object (a "request", for instance). A reference to these web services is added through the "Add Web Reference" menu in Visual Studio 2008, which, as you know, creates a proxy class for each endpoint which inherits from System.ServiceModel.ChannelBase<ISomeInterface> (where ISomeInterface is the endpoint defined by the specific service's WSDL).

现在的问题是,我想封装所有这些代理在一个单一的的ServiceManager (例如)静态包含类,例如,所有代理的内部列表,这样,一方面,所有调用给定服务可能会经历的ServiceManager ,而不是被分散在主应用程序,并且,在另一方面,新服务可加入后者可知道的ServiceManager 通过简单的增加一个参照新的代理类。

The question is that I would like to encapsulate all those proxies in a single ServiceManager (for instance) static class containing, for example, an internal list of all the proxies, so that, on the one hand, all calls to a given service may go through ServiceManager instead of being scattered around the main application, and, on the other hand, new services which may be added latter can be made known to ServiceManager by a simple addition of a reference to the new proxy class.

我想过desinging 的ServiceManager 喜欢

I thought about desinging ServiceManager like

public static class ServiceManager
{
    #region Properties

    public static Dictionary<string, TProxy> ServiceList { get; private set; }

    #endregion
}

但我不知道我应该替换 TProxy 以使所有的不同的代理可以通过使用被称为 ServiceManager.ServiceList [ 服务名称] 。任何人都可以请帮我这个?

but I don't know what I should replace TProxy by so that all of the different proxies can be called by using ServiceManager.ServiceList["ServiceName"]. Can anyone please help me out with this?

推荐答案

由于每个服务实现不同的接口,它必须是对象......除非你可以创建一个共同的基础接口,让代理人从该接口继承,然后创建一个列表&LT; MyBaseInterface&GT;

Since each service implements a different interface, it would have to be object... Unless you can create a common base interface, make the proxies inherit from that interface, and then create a List<MyBaseInterface>.

为什么你就不能对每个代理类一个属性?至少这样你可以访问一个强类型的方式代理。

Why can't you just have one property on your class per proxy? At least then you could access the proxies in a strongly-typed way.

这篇关于在静态类封装WCF代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 11:02