且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将服务引用添加到同一项目中的WCF服务

更新时间:2022-12-07 19:16:21

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

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).