简体   繁体   中英

wcf callback interface - implement third party interface

I have an interface definition which I want to share with other assemblies in the solution so I placed it in a separate project;

public interface IName
{
    string Name { get; }
}

However I want to use it in the project that defines the WCF callback interface:

public interface ICallback : IName
{
}

so I added the [OperationContract] attribute to the IName interface like so:

public interface IName
{
    string Name
    {
        [OperationContract(IsOneWay=false)]
        get;
    }
}

But when I use svcutil, the output class doesn't contain the inherited property. I've tried using the /r flag to reference the assembly containing IName but it still ignores the property.

I've even tried adding the [ServiceKnownType] attribute to the callback interface but still no luck:

[ServiceKnownType(typeof(IName))]
public interface ICallback : IName
{
}

Is it possible to implement an external interface in a WCF callback?

Yes, interface inheriting works with WCF.

Try to make the interfaces public (to be accessible in other assemblies, in your case it is internal).

I am not sure if WCF supports properties on public interfaces. Try it with some testing method instead of property on callback interfaces. WCF interface does not work in the same way as C# interface. WCF does not support overloading, for example. Try it this way:

public interface IName
{
    [OperationContract(IsOneWay=false)]
    string GetName();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM