c# - 如何在 WCF 服务中将接口(interface)作为参数传递?

标签 c# wcf

我有以下内容,但我不确定这是正确的做法。

namespace WCFServices
{
    [ServiceContract(Name = "IService")]
    [ServiceKnownTypeAttribute(typeof(DataItem))]
    public interface IService
    {
        [OperationContract]
        void InstantiateThirdParties(string name, IEnumerable<IDataItem> data, IEnumerable<string> modules, IEnumerable<string> states);
    }
}

这是使用接口(interface)的代码。

namespace WCFServices
{
    public class Service : IService
    {
        public void InstantiateThirdParties(string name, IEnumerable<IDataItem> data, IEnumerable<string> modules, IEnumerable<string> states)
        {
            Process.ExecuteAll(name, data, modules, states);
        }
    }
}

目前我唯一的对象类型如下。

namespace DataObjects
{
    [Serializable]
    [DataContract]
    public class DataItem : IDataItem
    {
        public DataItem();

        [DataMember]
        public CustomerInfo customer { get; set; }

        [DataMember]
        public LoanInfo loan { get; set; }

        [DataMember]
        public DateTime loanProcessingDate { get; set; }

        [DataMember]
        public string moduleID { get; set; }

        [DataMember]
        public string processingState { get; set; }
    }
}

我的方向是否正确?

最佳答案

您需要使用 KnownTypeAttribute 而不是 ServiceKnownTypeAttribute。

关于c# - 如何在 WCF 服务中将接口(interface)作为参数传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26611750/

相关文章:

WCF 服务名称和绑定(bind)名称

.net - 找不到WCF合约名称 'IMyService'?

C# 项目全局 AssemblyInfo

c# - 关于在后台线程中发送电子邮件,我应该知道些什么?网络

c# - 已安装 .Net 4.5 但无法在 Visual C# 中使用 ZipFile 类

Android 与 WCF Web 服务使用 ksoap2 - 错误 SoapFault - 故障代码 : ‘a:ActionNotSupported’

performance - WCF Windows 服务使用 100% cpu

c# - 如何将其他文件添加到 Visual Studio 2017 中的 NuGet 包?

javascript - 在 $http post 请求 header 或正文中插入自定义变量

c# - 为什么我不能使用 DataContractSerializer 序列化一个对象?