【问题标题】:How get reference to collection in WCF C#?如何在 WCF C# 中获取对集合的引用?
【发布时间】:2015-12-06 22:28:24
【问题描述】:

我在一个解决方案中有两个 WCF 服务:

  • Wcf.BLL
  • Wcf.model

我有一个额外的课程 RegistrationList 在服务 Wcf.model 使用以下代码:

 namespace Wcf.model
    {
        class RegistrationList
        {

            [Required]

            public string Login { get; set; }

            [Required]
            public string Password { get; set; }

        }
    }

如何从我的第一个服务Wcf.BLLServiceContract 访问RegistrationList,以设置RegistrationList 类型的参数?

[ServiceContract]
    public interface IWcf.BLL
    {

        [OperationContract]
        string Register(RegistrationList Login); // Here I can set type as `RegistrationList`

    }

【问题讨论】:

  • 您能否尝试提高您的问题的质量?不清楚你想做什么,也不清楚什么不起作用
  • 做了一些有问题的改动,希望更清楚
  • 您是否已经在 Wcf.BLL 中添加了对 Wcf.Model 的项目引用?
  • 是的,但是在Wcf.Model 里面我有单独的类(文件)RegistrationList

标签: c# wcf


【解决方案1】:

您没有为RegistrationList 类指定任何访问修饰符。默认为internal,因此仅在Wcf.model 程序集中可用。

如果您想在另一个程序集中使用RegistrationList,请将其设为public

public class RegistrationList
{
   //...
}

【讨论】:

  • 如果你想保持内部,你也可以添加 InternalsVisibleTo。
  • 这对我没有帮助。我没有看到 Wcf.model 中的类 RegistrationList 方法何时执行:Wcf.model.RegistrationList
  • 我确实要求在 WCF 服务中分离类,可能是它的原因吗?
  • @Ahmed 确保您在Wcf.BLL 中添加了对Wcf.Model 项目的引用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-20
  • 1970-01-01
相关资源
最近更新 更多