먼저 내 질문을 읽어 주셔서 감사합니다.ADO.NET Entity Framework (Vs2012 + WCF) = 오류
저는 VS 2012를 사용하여 ADO.NET Entity Framework (5 가지로 생각합니다, 최신 버전)를 사용하여 솔루션을 개발 중입니다. 비즈니스 레이어로 WCF 서비스를 소개하기 전까지는 모두 잘 작동합니다 (학교용 과제이므로 비즈니스 레이어에서 WCF를 스크랩 할 수 없음).
문제는 데이터베이스에서 데이터를 요청할 때입니다. 데이터베이스에서 문자열을 반환하는 메서드가있을 때이 메서드는 기본 함수부터 잘 작동합니다. 하지만 Entity 객체 (예 : Account)를 반환하면 모두 지옥에갑니다.
예외 : (예, 매우 모호합니다.) 나는 [DataContract] [DataMember를] 속성을 추가 할 수 Entites.tt 파일을 수정 시도 : 나는 시도 무엇
An error occurred while receiving the HTTP response to http://localhost:8733/Services/AccountsManager. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
. 이것은 이전 버전의 EF에서는 자체적으로 수행하는 것처럼 보였기 때문입니다. 그러나 컴파일이 가능하고 직렬화가 불가능하다고 불평하지 않기 때문에 이것이 필요한지는 알 수 없습니다.
이것은 처음 모습입니다 :
namespace CommonLayer
{
using System;
using System.Collections.Generic;
public partial class Account
{
public Account()
{
this.Transactions = new HashSet<Transaction>();
this.Transactions1 = new HashSet<Transaction>();
}
public System.Guid ID { get; set; }
public int Type { get; set; }
public string Name { get; set; }
public int Currency { get; set; }
public decimal Balance { get; set; }
public System.DateTime DateOpened { get; set; }
public Nullable<int> Duration { get; set; }
public string UserName { get; set; }
public virtual AccountType AccountType { get; set; }
public virtual Currency Currency1 { get; set; }
public virtual User User { get; set; }
public virtual ICollection<Transaction> Transactions { get; set; }
public virtual ICollection<Transaction> Transactions1 { get; set; }
}
}
는 수정 후 보이는 방법 :
namespace CommonLayer
{
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
[DataContract] public partial class Account
{
public Account()
{
this.Transactions = new HashSet<Transaction>();
this.Transactions1 = new HashSet<Transaction>();
}
[DataMember] public System.Guid ID { get; set; }
[DataMember] public int Type { get; set; }
[DataMember] public string Name { get; set; }
[DataMember] public int Currency { get; set; }
[DataMember] public decimal Balance { get; set; }
[DataMember] public System.DateTime DateOpened { get; set; }
[DataMember] public Nullable<int> Duration { get; set; }
[DataMember] public string UserName { get; set; }
public virtual AccountType AccountType { get; set; }
public virtual Currency Currency1 { get; set; }
public virtual User User { get; set; }
public virtual ICollection<Transaction> Transactions { get; set; }
public virtual ICollection<Transaction> Transactions1 { get; set; }
}
}
모든 포인터는 크게 감사하고 있습니다.
내 WCF 클래스
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLayer
{
[ServiceContract]
interface IAccountsManager
{
[OperationContract]
List<CommonLayer.Account> GetAccounts(String UserName);
[OperationContract]
String GetData();
[OperationContract]
CommonLayer.Account GetAccount(String UserName);
}
class AccountsManager: IAccountsManager, IDisposable
{
public List<CommonLayer.Account> GetAccounts(String UserName)
{
return DataLayer.AccountsRepository.Instance.GetAccountList(UserName).ToList();
}
public String GetData()
{
CommonLayer.Account acc = this.GetAccounts("test").FirstOrDefault();
return acc.DateOpened.ToString();
}
public CommonLayer.Account GetAccount(String UserName)
{
return this.GetAccounts(UserName).FirstOrDefault();
}
public void Dispose()
{
DataLayer.AccountsRepository.Reset();
}
}
}
질문을 편집하고 WCF 서비스 메서드를 추가 할 수 있습니까? –
요청에 따라 수정 됨. 이러한 메서드에서 "GetData 메서드 작동". 다른 방법은 그렇지 않습니다. –