Search code examples
c#wcf

reference methods from interface through a WCF service


Say I have the following:

namespace SomeProject
{
    public interface ISomething
    {
        string SomeMethod();
    }
}

namespace SomeService
{
    [DataContract]
    public class CompositeType
    {
        [DataMember]
        public ISomething Something { get; set; }
    }
}

Now, in my calling code I want to be able to do this:

SomeService service = new SomeService();
service.Something.SomeMethod();

SomeMethod() is not available unless I return the DataMember as the implementation rather than the interface. Is there a way to do this?


Solution

  • This is not how you want to use your WCF service. WCF is about transferring data, not implementation. You are confusing your client and your service layers by doing this.

    However, if you really want to do this, you can tell the proxy generator in the client to re-use any existing types... this means that you can

    1. reference the "SomeProject" dll in your client
    2. add the service reference
    3. choose "Advanced"
    4. Select "Reuse types in referenced assemblies"
    5. Choose where you want to get the types from

    Again, I do not recommend doing it this way.