开发者

Service References vs Assemblies References, using WCF Services

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. use Service Reference (use WDSL) to URL Publish of WCF Service;
  2. use Assembly Reference to assembly contains Interfaces, Contracts, DataCo开发者_如何学Gontracts classes.

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

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


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.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜