0
我有3個項目AC#解決方案:C#WCF隨着POCO DataContract
- 模型(EF POCO類)
- WCF服務
- 客戶端(主要的應用程序)
在項目我有型號僱員:
[Table("employee")]
public class Employee
{
[Key, Column("organizationid", TypeName = "uniqueidentifier", Order=0)]
public Guid OrganizationId { get; set; }
[Key, Column("personid", TypeName = "uniqueidentifier", Order=1)]
public Guid PersonId { get; set; }
[Column("jobtitle", TypeName = "nvarchar")]
public String JobTitle { get; set; }
[Column("active", TypeName = "bit")]
public Boolean Active { get; set; }
[Column("telecom", TypeName = "nvarchar")]
public String Telecom { get; set; }
[Column("email", TypeName = "nvarchar")]
public String Email { get; set; }
[Column("confidentialitycode", TypeName = "nvarchar")]
public String ConfidentialityCode { get; set; }
[Column("priority", TypeName = "int")]
public Int32 Priority { get; set; }
#region Foreign Relations
[ForeignKey("OrganizationId")]
public virtual Organization CurrentOrganization { get; set; }
[ForeignKey("PersonId")]
public virtual Person CurrentPerson { get; set; }
#endregion
}
然後,我創建了一個WCF服務名爲Test.svc認爲有以下幾點:
public class Test : ITest
{
public Model.POCO.Employee DoWork()
{
Model.POCO.Employee newItem = new Model.POCO.Employee();
newItem.PersonId = Guid.NewGuid();
newItem.OrganizationId = Guid.NewGuid();
newItem.Priority = 1;
newItem.Telecom = "";
newItem.JobTitle = "";
newItem.Email = "";
newItem.Active = true;
return newItem;
}
}
[ServiceContract]
public interface ITest
{
[OperationContract]
Model.POCO.Employee DoWork();
}
在我添加了一個按鈕,並在單擊事件的客戶端的項目,我有這樣的代碼:
private void button1_Click(object sender, EventArgs e)
{
DataReference.WCFTest.TestClient svc = new DataReference.WCFTest.TestClient();
var employee = svc.DoWork();
svc = null;
}
如果我看着「變種員工」我可以看到,對象是存在的,是偉大的工作,但「員工」是不是Model.POCO.Employee類型,反而是WCFTest.Employee類型。
如何讓我的WCF服務返回Model.POCO.Employee?有沒有解決這個問題的方法?或者我可以將WCFTest.Employee自動包裝到Model.POCO.Employee?
非常感謝。
偉大的工程!我可以爲WCF數據服務參考做同樣的事嗎? – VAAA
這應該只是工作。 – CodeCaster
我已經嘗試了WCF數據服務,但它不工作...... :( – VAAA