简体   繁体   English

wcf回调接口-实现第三方接口

[英]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: 但是我想在定义WCF回调接口的项目中使用它:

public interface ICallback : IName
{
}

so I added the [OperationContract] attribute to the IName interface like so: 所以我将[OperationContract]属性添加到IName接口,如下所示:

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

But when I use svcutil, the output class doesn't contain the inherited property. 但是,当我使用svcutil时,输出类不包含继承的属性。 I've tried using the /r flag to reference the assembly containing IName but it still ignores the property. 我尝试使用/ r标志来引用包含IName的程序集,但它仍会忽略该属性。

I've even tried adding the [ServiceKnownType] attribute to the callback interface but still no luck: 我什至尝试将[ServiceKnownType]属性添加到回调接口,但还是没有运气:

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

Is it possible to implement an external interface in a WCF callback? 是否可以在WCF回调中实现外部接口?

Yes, interface inheriting works with WCF. 是的,接口继承可用于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. 我不确定WCF是否支持公共接口上的属性。 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接口与C#接口的工作方式不同。 WCF does not support overloading, for example. 例如,WCF不支持重载。 Try it this way: 尝试这种方式:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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