服务参考 C# 上缺少已发布的 类

Missing Published Classes on Service Reference C#

第一次来这里,从来不用问什么,因为在其他问题中总是很容易找到答案。

我面临的问题:

我刚刚添加了 ServiceLayer,它将发布与 BusinesLogicLayer 相对应的服务。

所以这是我的代码:

using Shared.Entities;
using System;
using System.Collections.Generic;
using System.Linq; 
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

namespace ServiceLayer
{
[ServiceContract]
public interface IServiceEmployees
{
    [OperationContract]
    void AddEmployee(Employee emp);

    [OperationContract]
    void DeleteEmployee(int id);

    [OperationContract]
    void UpdateEmployee(Employee emp);

    [OperationContract]
    List<Employee> GetAllEmployees();

    [OperationContract]
    Employee GetEmployee(int id);

    [OperationContract]
    double CalcPartTimeEmployeeSalary(int idEmployee, int hours);
}
}

下一个文件:

using BusinessLogicLayer;
using Shared.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace ServiceLayer
{
public class ServiceEmployees : IServiceEmployees
{
    private static IBLEmployees blHandler;

    public ServiceEmployees()
    {
        blHandler = Program.blHandler;
    }

    public void AddEmployee(Employee emp)
    {
        blHandler.AddEmployee(emp);
    }

    public void DeleteEmployee(int id)
    {
        blHandler.DeleteEmployee(id);
    }

    public void UpdateEmployee(Employee emp)
    {
        blHandler.UpdateEmployee(emp);
    }

    public List<Employee> GetAllEmployees()
    {
        return blHandler.GetAllEmployees();
    }

    public Employee GetEmployee(int id)
    {
        return blHandler.GetEmployee(id);
    }

    public double CalcPartTimeEmployeeSalary(int idEmployee, int hours)
    {
        return blHandler.CalcPartTimeEmployeeSalary(idEmployee, hours);
    }
    }
    }

下一个文件:

     using System;
     using System.Collections.Generic;
     using System.Linq;
     using System.Text;
     using System.Threading.Tasks;
     using System.Runtime.Serialization;

     namespace Shared.Entities
     {

     [DataContract]
     [KnownType(typeof(FullTimeEmployee))]
     [KnownType(typeof(PartTimeEmployee))]
     public abstract class Employee
     {
    [DataMember]
    public int Id { get; set; }
    [DataMember]
    public string Name { get; set; }
    [DataMember]
    public DateTime StartDate { get; set; }
    }
    }

下一个文件:

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Runtime.Serialization;

  namespace Shared.Entities
  {
[DataContract]
public class FullTimeEmployee : Employee
{
    [DataMember]
    public int Salary { get; set; }
}
}

最后一个文件:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Runtime.Serialization;

    namespace Shared.Entities
    {
    [DataContract]
    public class PartTimeEmployee : Employee
    {
    [DataMember]
    public double HourlyRate { get; set; }
    }
    }

好吧,这些是我需要在 wsdl 中发布以供以后使用,而不是在 PresentationLayer 中访问 BusinessLayer 和 DataLayer。

我已经成功地发布了那些 OperationContracts,并且 当我在 PresentationLayerWinForm 上添加 url 作为服务参考时,我得到以下信息。

wsdl description

我需要在该描述中看到 Employee.cs、PartTimeEmployee、FullTimeEmployee 类,但我没有得到它们,尽管它们在 wsdl 中定义。

wsdl_2

可能出了什么问题?

我已经清理了我的项目,重新构建了几次,但我仍然得到同样的结果,我需要发布这些课程,所以我从 PresentationLayerWinForm

中删除了对 shared.entities 的引用

感谢4位帮助,

问题已解决;

问题是我的服务器端 DataContract class 的名称与 class 相同,我在本地使用 Web 服务的客户端,所以 Visual Studio 重新- 默认使用类型。右键单击服务引用,单击配置并关闭类型重用。

谢谢。