服务引用VS集的引用,使用WCF服务 [英] Service References vs Assemblies References, using WCF Services

查看:138
本文介绍了服务引用VS集的引用,使用WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WCF服务(与servicecontracts,datacontracts等),像这样的:

I have a WCF Service (with servicecontracts, datacontracts, etc) , like this:

[ServiceContract(Namespace = "http://company.com/MyCompany.Services.MyProduct")]
public interface IService
{
    [OperationContract]
    CompositeType GetData();
}

[DataContract(Namespace = "http://company.com/MyCompany.Services.MyProduct")]
public class CompositeType
{
    // Whatever
}

如果我想在客户端使用的服务,我认为有两个选项:

If I want to use the service in a client, I think there are two options:


  1. 使用服务引用(使用WDSL)到URL发布WCF服务的;

  2. 使用装配参考组件包括接口,合同,DataContracts类。

我用.NET到.NET的场景在90%以上。

I use .NET to .NET scenarios in 90%.

这是最好的办法吗?其中对方的优点?

Which is the best way? which the advantages of each other?

推荐答案

如果你真的想利用你作为服务的服务,那么你就必须使用服务引用。否则,你只是添加依赖于另一个DLL,就像任何其他程序集引用。

If you truly want to make use of your Services as Services, then you'll have to use Service References. Otherwise, you're just adding a dependency to another DLL, just like any other assembly reference.

另外...如果你的服务连接到任何类型的数据库或网络资源,将只能活在服务器上的,服务引用确实是你唯一的选择。如果添加大会参考,客户端将尝试向资源......其中,超过可能,不应该公开的直接连接。

Also...if your services are connecting to any kind of Database or network resource that will only live on a server, a Service Reference is really your only choice. If you add an Assembly reference, the client will attempt to make a direct connection to the resource...which, more than likely, shouldn't be publicly available.

要增加一个直接装配参考,而不是一个服务引用的好处是,你不必去通过所有的开销,调用code作为一个服务添加(Web服务器处理的请求,您的实例服务,序列中的对象,执行所述code,序列化的结果,并通过所有备份到客户端)。

The benefit to adding an direct assembly reference rather than a service reference is the fact that you won't have to go through all the overhead that calling code as a service adds (web server handling the request, instantiating your service, serializing the objects, executing the code, serializing the result, and passing that all back up to the client).

这篇关于服务引用VS集的引用,使用WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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