2016-04-11 28 views
0

ここに初めて、何か質問する必要はありませんでした。公開されているサービスクラスの公開クラスがありませんC#

問題私が直面している:

私はちょうどBusinesLogicLayerにサービスのcorrespondantを公開しようとしているServiceLayerを追加しました。

だから、これは私のコードです:

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

オールライト、それらは私が代わりにBusinessLayerとDataLayerにプレゼンテーション層にアクセスするので、後に消費するWSDLでパブリッシュを取得する必要があるものです。

公開されているこれらのOperationContractsを問題なく使用できました。 私はPresentationLayerWinFormのサービス参照としてURLを追加すると、次のようになります。私はEmployee.cs、PartTimeEmployeeを参照してくださいする必要があり

wsdl description

、FullTimeEmployeeはその説明に同様clasesしかし、私は、彼らがWSDLで定義されているが、それらを得るいけません。

wsdl_2

は何がおそらく間違っていたのだろうか?

アイブ氏は、私のproyectを掃除し、それをrebuiled数回、私はまだ同じものを取得し、私はそれらのclasesが

おかげで4貢献し、

をので公開し、私はPresentationLayerWinForm

からshared.entitiesへの参照をerrase取得TE必要

答えて

0

問題が解決しました。

問題は、サーバー側のDataContractクラスの名前が、Webサービスのクライアントにローカルであるクラスと同じであるため、Visual Studioはデフォルトで型を再利用することです。 「サービスリファレンス」を右クリックし、「構成」をクリックして、「タイプ再利用」をオフにします。

ありがとうございます。

関連する問題