Kiquenet
Kiquenet

Reputation: 14986

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

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

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

Upvotes: 1

Views: 741

Answers (1)

Justin Niessner
Justin Niessner

Reputation: 245399

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

Upvotes: 1

Related Questions