saidinarts

With Remoting, it was very easy to switch between calling a MarshalByRefObject remotely or locally, just by the entry within the configuration file. I would like to keep this ability with WCF, so that our clients have the ability to either use the classes locally in memory, or a remote call. I have made some alterations to get this to work, but would like to know if there are any repercussions doing so. I have my ServiceContract:

Code Snippet

[ServiceContract(Namespace = "http://Platform")]

public interface IPersonServices

{

[OperationContract]

Person Get(PersonBase person);

}

After utilizing the svcutil to generate the PersonServices.cs file, I comment out the generated IPersonServices and Person class. I now make a reference to the wcf DLL from the client application, and have the generated PersonServicesClient inherit from the original IPersonServices. I also have to make a change in the client config file to have the contract of the endpoint to be against the original interface.

Now, in the client code, I look for a boolean value to indicate to me if I use it locally or as a remote call:

Code Snippet

IPersonServices client;

bool local = false;

if (local)

client = new PersonServices();

else client = new PersonServicesClient("NetTcpBinding_IPersonServices");

PersonBase[] persons = client.GetList();

if (client is PersonServicesClient)

((PersonServicesClient)client).Close();

As I stated, this functionally works, but I don't know if I'm screwing something up with wcf internally by doing such alterations to the generated code. Perhaps there is already a way of doing this by a simple entry and I just don't know it, like a local binding value - something that I've never seen yet. Either way, please let me know. Thanks in advance.



Re: Windows Communication Foundation (Indigo) Utilizing ServiceContracts locally or remotely

BenK

I wouldnt alter the proxy as you have to reapply the change everytime you make a server change such as adding a new method. Put a abstraction level in before calling the proxy or even better have different comms DLL's

Regards,

Ben





Re: Windows Communication Foundation (Indigo) Utilizing ServiceContracts locally or remotely

Christian Weyer

As Ben suggests I would use a proxy factory that hides this code - I have built a generic ProxyFactory<T> that can use Local, Remoting, ASMX or WCF.






Re: Windows Communication Foundation (Indigo) Utilizing ServiceContracts locally or remotely

saidinarts

Great suggestion, this would ensure that I'm not messing up the generated code process. Thanks for the input.