将服务引用添加到同一项目中的WCF服务 [英] Add Service Reference to WCF Service within Same Project

查看:226
本文介绍了将服务引用添加到同一项目中的WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将服务引用添加到在同一VS项目中定义了被引用服务的项目中,这是一种可接受的编程做法吗? (服务和服务参考位于同一项目中)

Is it an acceptable programming practice to add a Service Reference to a Project where the Service being referenced is defined within the same VS Project? (Service and Service Reference are in the same Project)

示例:

MyWebAppProj
-服务
--MyService
-服务参考
--MyServiceServiceReference.MyServiceClient
-Default.aspx.cs使用MyServiceServiceReference.MyServiceClient

MyWebAppProj
-Services
--MyService
-Service References
--MyServiceServiceReference.MyServiceClient
-Default.aspx.cs uses MyServiceServiceReference.MyServiceClient

其背后的原因是可以将Silverlight应用程序添加到项目中.如果是这样,我们将必须通过服务层公开所有业务逻辑方法,所以为什么不先这样做并在各处使用它们以保持网页和Silverlight页面之间的标准化.

The rational behind this is that a Silverlight App may be added to the Project. If it is, we would have to expose all the Business Logic methods through a service layer, so why not just do that first and use them everywhere to stay standardized between web pages and Silverlight pages.

推荐答案

我根本看不出为什么要这么做.

I can't see why you would want to do that at all.

如果您已经与服务位于同一个项目中,那么至少您已经可以访问所有服务/数据合同,因此,实际上,调用服务已经非常非常容易.您可以直接使用ChannelFactory,也可以编写自己的自定义ClientBase< T派生的客户端代理类(很简单),在这种情况下没有 理由想要添加服务引用

If you're already inside the same project as the service, at the very least you've already got access to all the service/data contracts, so really, calling the service is already very, very easy. You can either use a ChannelFactory directly, or write your own custom ClientBase<T>-derived client proxy class (which is trivial), there's no reason why you'd want to add service reference in this case.

此外,如果添加了服务引用,那么您将在同一项目中陷入一堆重复的定义,这毫无意义(是的,您可以将生成的代码隔离到单独的命名空间中,但仍然可以)

Furthermore, if you added a service reference, you'd then be stuck with a bunch of duplicate definitions in the same project, which makes little sense (yes, you can isolate the generated code into a separate namespace, but still).

这篇关于将服务引用添加到同一项目中的WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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