如何在 WCF 服务中将接口作为参数传递? [英] How to pass Interface as parameter in WCF service?

查看:32
本文介绍了如何在 WCF 服务中将接口作为参数传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the following however I am not sure this is the correct way of doing it.

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);
    }
}

这是使用接口的代码.

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);
        }
    }
}

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

and my only object type at the moment is the following.

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.

You need to use the KnownTypeAttribute instead of the ServiceKnownTypeAttribute.

这篇关于如何在 WCF 服务中将接口作为参数传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆