wcfweb-servicestransparentproxy

How to create a WCF web service within an ASP.NET application that can return instances of an interface as a transparent proxy


My use-case:

Here’s what I tried (please tell me where I went wrong):

How do I fix this so that I get the IWorkInterface transparent proxy that I expect?

Things I’ve tried

What am I doing wrong?


Solution

  • The use-case I am describing is not directly supported by WCF.

    The accepted work-around is to return an instance of EndpointAddress10 which points to the service for the “other” interface. The client must then manually create a Channel to access the remote object. WCF doesn’t properly encapsulate this process.

    An example that demonstrates this is linked to from the MSDN article “From .NET Remoting to the Windows Communication Foundation (WCF)” (find the text that says “Click here to download the code sample for this article”). This example code demonstrates both .NET Remoting as well as WCF. It defines an interface that looks like this:

    [ServiceContract]
    public interface IRemoteFactory
    {
        IMySessionBoundObject GetInstance();
        [OperationContract]
        EndpointAddress10 GetInstanceAddress();
    }
    

    Notice that the interface-returning method is not part of the contract, only the one that returns an EndpointAddress10 is marked with [OperationContract]. The example calls the first method via Remoting, where it correctly creates a remote proxy as one would expect — but when using WCF it resorts to the second method and then instantiates a separate ChannelFactory with the new endpoint address to access the new object.