views:

28

answers:

1

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, DataContracts classes.

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

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

+1  A: 

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

Justin Niessner
Assembly reference only the inteface (contracts), the implementation is a WCF Services. Only I add reference to ServiceContracts in clients.
alhambraeidos