Stefan Schmid
Stefan Schmid

Reputation: 1042

Combine multiple interfaces into one main interface

I want to declare multiple interfaces for my WCF Service. These interfaces should go into one main interface by implementing them. This works in Visual Studio, but when I start my WCF Service it crashes, because the multiple interfaces are missing the ServiceContract attribute. I don't want to add this attribute to them, because the client should only use my main interface which has the ServiceContract attribute.

Here's one of the small interfaces:

public interface IBroadcastHostFunctions
{
    [OperationContract]
    void SubscribeToBroadcasts();

    [OperationContract]
    void UnsubscribeFromBroadcasts();
}

This is the main interface as is should look like:

[ServiceContract(CallbackContract = typeof (IHostFunctionsCallback))]
public interface IHostFunctions : IBroadcastHostFunctions
{
}

Does anyone know how to realize this without adding the ServiceContract attribute to IBroadcastHostFunctions?

Upvotes: 0

Views: 262

Answers (1)

Xharlie
Xharlie

Reputation: 2540

When publishing a WCF service, you cannot (and should not) control the interface types that consumers use to create client-proxies for it. They are free to define their own interface or generate one with a tool (from the WSDL) and, as long as it conforms to your service's contract, it will work.

The only possible reason to avoid decorating IBroadcastHostFunctions with ServiceContract would be to avoid a dependency on System.ServiceModel but you have decorated the methods on IBroadcastHostFunctions with OperationContract attributes so that type already requires System.ServiceModel.

Go ahead and add ServiceContract to IBroadcastHostFunctions and let your consumers run free.

Upvotes: 1

Related Questions