[英]Missing Published Classes on Service Reference C#
First time here, never had the need to ask for anything due it was always easy to find the answer in other questions made. 第一次来这里,因为在其他问题上总是很容易找到答案,所以不需要任何要求。
The problem i'm facing: 我面临的问题:
I've just added the ServiceLayer which is going to publish services correspondant to BusinesLogicLayer. 我刚刚添加了ServiceLayer,它将发布与BusinesLogicLayer相对应的服务。
So this is my code: 这是我的代码:
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);
}
}
Next file: 下一个文件:
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);
}
}
}
Next file: 下一个文件:
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; }
}
}
Next Files: 下一个文件:
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; }
}
}
Last File: 最后文件:
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; }
}
}
Allright, those are the ones i need to get published in a wsdl to consume later instead of accessing in PresentationLayer to BusinessLayer and DataLayer. 好了,这些是我需要在wsdl中发布以供以后使用而不是在PresentationLayer中访问BusinessLayer和DataLayer的那些。
I've managed to get the published those OperationContracts without problems, and when i add the url as an service reference on the PresentationLayerWinForm , i get the following. 我设法毫无问题地发布了那些OperationContracts,当我在PresentationLayerWinForm上将URL作为服务引用添加时,我得到了以下内容。
I need to see the Employee.cs, PartTimeEmployee, FullTimeEmployee clases as well in that description but i dont get them although they are defined in the wsdl. 在该说明中,我还需要查看Employee.cs,PartTimeEmployee,FullTimeEmployee的分类,但是尽管它们是在wsdl中定义的,但我没有得到它们。
What could possibly went wrong ? 可能出了什么问题?
Ive cleaned my proyect, rebuiled it several times and i still get the same thing, and i need those clases te get published so i errase the reference to shared.entities from PresentationLayerWinForm 我已经清理了我的proyect,将其重新构建了好几次,我仍然得到同样的东西,我需要发布这些案例,所以我从PresentationLayerWinForm中删除了对shared.entities的引用。
Thanks 4 helping, 感谢4的帮助,
Problem Solved; 问题解决了;
The issue was that my server-side DataContract class is named the same as a class i'm using local to the client of the web service, so Visual Studio re-uses types by default. 问题是我的服务器端DataContract类的名称与我在Web服务客户端本地使用的类的名称相同,因此Visual Studio默认情况下会重用类型。 Right-click on the Service Reference, Click on Configure and turn off Type re-use.
右键单击“服务参考”,单击“配置”,然后关闭“类型重用”。
Thanks Anyway. 不管怎么说,还是要谢谢你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.