Question

I have a c# solution with 3 projects:

  1. Models (EF POCO Classes)
  2. WCF Services
  3. 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.

Was it helpful?

Solution

How can I make my WCF service return the Model.POCO.Employee?

It does, your client just doesn't know about that type.

Reference the Models project from your client project and make sure at "Configure Service Reference" (or under Advanced when creating one) that at "Reuse types" the Models assembly is checked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top