WCF 服务返回另一个服务(服务工厂?)
我们使用 WCF 在客户端和服务器应用程序之间进行通信。客户端应用程序具有许多需要与服务器通信的功能 - 我们选择在多个类中实现此功能(职责分离)
目前,我们正在为每个对象创建新的 WCF 端点和服务契约 - 发票、会计、内容管理等。这会导致客户端和服务器上进行大量端点配置(在进入测试和生产平台时可能会出现配置错误问题)。
我想知道是否可以定义一个可以提供多个服务联系实现的 WCF 端点。然后,我们的配置文件将包含单个端点(到服务工厂),我可以通过指定我感兴趣的服务的接口来请求不同的服务。
例如,
using (IServiceClientFactory serviceClientFactory = new RealProxyServiceClientFactory())
{
// This is normal WCF proxy object creation.
IServiceFactory serviceFactory = serviceClientFactory.CreateInstance<IServiceFactory>("");
// This is what we would like to do
IInvoiceService invoiceService = serviceFactory.getService(typeof(IInvoiceService));
invoiceService.executeOperation(data);
}
线索是每个客户端/服务器对的单个端点配置,而不是我希望提供每个服务联系人的端点配置。
这可能吗?
We are using WCF for communication between a client and a server application. The client application has many features that requires communication to the server - and we have chosen to implement this in multiple classes (seperation of responsability)
For the time, we are creating new WCF endpoints and service contracts for each object - Invoicing, Accounting, Content Management, etc. This causes a lot of endpoint configuration both on the client and server (with potential misconfiguration problems when moving into the test and production platforms).
I would like to know if I can define a single WCF endpoint that can deliver multiple service contact implementations. Our configuration files would then contain a single endpoint (to the service factory) and I can request different services by specifying the interface of the service I am interested in.
e.g.
using (IServiceClientFactory serviceClientFactory = new RealProxyServiceClientFactory())
{
// This is normal WCF proxy object creation.
IServiceFactory serviceFactory = serviceClientFactory.CreateInstance<IServiceFactory>("");
// This is what we would like to do
IInvoiceService invoiceService = serviceFactory.getService(typeof(IInvoiceService));
invoiceService.executeOperation(data);
}
The clue being a single endpoint configuration per client/server pair, instead of an endpoint configuration per service contact I would like to make available.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我怀疑这是否有效。 Xml 序列化可能是这里最大的问题。
我也不认为你真的需要它。如果我处于你的立场,我会尝试抽象我与服务的通信。基本上,您总是会向服务发送一条“消息”,该服务的“目标”是您想要访问的类之一。该服务总是会回复一个“响应”,其中的内容将由“消息”发送到的类填充。
另一种方法是通过服务路由所有这些消息,该服务将请求回显到适当的服务。通过这种方式,您可以保持可扩展性,但仍然有很大的配置负担。
HTH。
I doubt that this would work. Xml serialization might be the biggest problem here.
Also I don't think you actually need it. If I was in your shoes I would try and abstract my communication with the service. Basically you would always send a "Message" to the service, which has a "Target" being one of the classes you wanted to access. The service would always reply with a "Response", of which the contents would be filled by the class the "Message" was send to.
Another approach would be to route all these messages trough a service that would echo the request to the appropriate service. This way you keep scalability up, but it does still have a large configuration burden.
HTH.
听起来您想保留单独的服务,但拥有某种路线贯通的巴士。也许是 MSMQ,那么您可以拥有一个服务,将每条消息弹出到特定队列中,然后专用服务可以从该特定队列中读取该消息。
诚然,这并不是一个真正基于 WCF 的解决方案。
由多个类实现的单个接口(读作 ServiceContract)的概念是行不通的。因此,您需要一项“怪物”服务来实现所有功能并路由到正确的服务。立面图案浮现在脑海中。
Sounds like you want to keep your seperate services but have some kind of bus that routes is throught. MSMQ maybe, then you can have one services that takes every message pops it onto a specific queue and then a dedicated service can read that off that particular queue.
Not really a WCF based solution though admittedly.
The notion of a single interface(read as ServiceContract) implemented by multiple classes wont work. So you'd need one 'monster' service that implements all and routes through to the correct service. Facade pattern springs to mind.
我不是 100% 清楚你想要做什么,但如果你只是想能够在同一个地址上托管不同的合约,并在一个服务类中实现,那么这是完全可能的。要共享端点地址,您必须确保为每个服务端点使用相同的绑定实例。
这是一个完整的示例,它定义了 3 个合约、1 个实现所有合约的服务类,以及一个具有 3 个合约端点位于完全相同地址的 ServiceHost:
I'm not 100% clear on what you're trying to do, but if you just want to be able to host different contracts on the same address with the implementation inside one service class, this is completely possible. To share an endpoint address, you must ensure that you use the same binding instance for each service endpoint.
Here is a complete sample which defines 3 contracts, 1 service class which implements all of them, and a ServiceHost with the 3 contract endpoints at the exact same address: