WCF和接口继承 - 这是一个可怕的事是什么? [英] WCF and Interface Inheritance - Is this a terrible thing to do?

查看:203
本文介绍了WCF和接口继承 - 这是一个可怕的事是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有2个服务,让我们说一个是基本的(整数)计算器,一个是浮点运算。我EX preSS这些像这样的接口:

My application has 2 "services", let's say one is a basic (integer) calculator, and one is a floating point calculator. I express these as interfaces like so:

public interface IBasicCalculator
{
	int Add( int a, int b );
}

public interface IFloatingPointCalculator
{
	double Add( double a, double b );
}

我想通过WCF暴露这些。不幸的是WCF似乎很紧缚,你要公开必须通过一个单一的服务接​​口,每一个可能的操作概念 - 你不能共享服务之间的会话,它是从客户端麻烦,因为你需要创建一个为每一个单独的代理,但似乎没有任何子服务,等等...

I want to expose these via WCF. Unfortunately WCF seems to be very tightly tied to the notion that every possible operation you want to expose must go through one single service interface -- you can't share sessions between services, it is cumbersome from the client side as you need to create a seperate proxy for each one, there don't seem to be any "sub-services", etc...

所以,我收集了,我需要present组合接口(一个也可能称之为一个门面),像这样的:

So, I've gathered that I need to present a "combined" interface (one might also call it a facade), like this:

[ServiceContract]
public interface ICalculatorService : IBasicCalculator, IFloatingPointCalculator
{
	[OperationContract(Name = "AddInt")]
	new int Add( int a, int b );

	[OperationContract(Name = "AddDouble")]
	new double Add( double a, double b );
}

如果我这样做,那么WCF暴露了这两种方法的客户端,可以打电话给他们,而这一切实际工作。

If I do this, then WCF exposes both methods to the client, which can call them, and it all actually works.

不过,继承接口一样,似乎是笨拙。 尤其的在 内部添加 双击添加。严格来说,上的方法表示隐藏潜在的方法,我没有真正做的事。我可以省略,但当时我只是得到数额为我想我躲在这个方法,你需要将其重命名方法或把'新'的编译器警告就可以了。

However, "inheriting the interfaces" like that seems to be ungainly. Particularly the new int Add and new double Add. Strictly speaking, new on a method indicates hiding an underlying method, which I'm not actually doing at all. I can omit the new, but then I just get compiler warnings which amount to "I think I'm hiding this method, you need to rename it method or put 'new' on it".

所以,这是一个2部分的问题:

So, this is a 2-part question:

  1. 我是在跟踪我相结合的一切到一个界面的逻辑,还是有实际的方式来揭露子服务或多个链接服务使用WCF?

  1. Am I on track with my 'combine everything into one interface' logic, or is there actually a way to expose "sub-services" or "multiple linked services" using WCF?

如果这是需要做的事情,有没有更好的办法?

If this is what needs to be done, is there a better way?

谢谢!

推荐答案

我只是工作了,您可以公开多个终结点(每个使用不同的接口),以同样的服务,而你仍然只需要生成的一个代理的lib客户端,可以访问所有这些,它完全解决了我的问题。

I just worked out that you can expose multiple endpoints (each using a different interface) to the same service, and you still only need generate ONE proxy lib on the client which gives access to all of them, which solves my problem entirely.

这篇关于WCF和接口继承 - 这是一个可怕的事是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆