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.
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.
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.
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.
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
Thanks 4 helping,
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. Right-click on the Service Reference, Click on Configure and turn off Type re-use.
Thanks Anyway.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.