I have a c# solution with 3 projects:
- Models (EF POCO Classes)
- WCF Services
- Client (main app)
Under project Models I have a model Employee:
[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
}
Then I created a WCF Service named Test.svc that has the following:
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();
}
In the client project I have added a button and on the click event I have this code:
private void button1_Click(object sender, EventArgs e)
{
DataReference.WCFTest.TestClient svc = new DataReference.WCFTest.TestClient();
var employee = svc.DoWork();
svc = null;
}
If I look into "var employee" I can see that the object is there and is working great but "employee" is not Model.POCO.Employee type, instead is WCFTest.Employee type.
How can I make my WCF service return the Model.POCO.Employee? Is there any workaround to this? Or can I autowrap WCFTest.Employee to Model.POCO.Employee?
Thanks a lot.