Steve B
Steve B

Reputation: 37660

Switching between in-memory and WCF service?

Imagine I have the following, standard WCF, code :

[ServiceContract]
interface ICustomerService {
    [OperationContract]
    Customer GetCustomer();
}

public ICustomerService {
     public Customer GetCustomer() 
     { 
          return MyStore.WhatIsNeeded();
     }
}

This is working well and allows me to distribute the service and the consuming code.

Is it possible (and is it a good idea) to completely bypass the WCF engine if working in a single box ?

In fact, I want the app to be able to run on farm servers, or on small single box servers.

To reduce WCF messaging cost, I'd like to have something like :

ICustomerService service = null;
if(singlebox)
{
    service = new CustomerService(); // Direct instanciation of the service class. No WCF here ...
}
else
{
    service = new CustomerServiceClient(); // Wcf client
}

var cust = service.GetCustomer();

If wrapped properly, can this technique reduce server charge ?

Upvotes: 0

Views: 166

Answers (2)

Kiran Mothe
Kiran Mothe

Reputation: 685

This will surely reduce the overhead of WCF runtime. I'd create a factory class which will check if(singlebox) and new up the right implementation of ICustomerService.

Upvotes: 0

Sixto Saez
Sixto Saez

Reputation: 12680

That won't work because the client will be attempting to access an endpoint for a service that no longer is exposing one. The WCF plumbing is required for the both the service and the client. For single box scenarios, look at the NetNamedPipeBinding which is the WCF plumbing done through the equivalent of shared memory.

Upvotes: 1

Related Questions