Is there a clean way of using the auto-generated EF classes with WCF instead of having to hand-make classes for WCF DataContracts?
The classes are located in the LAIT.Entities.dll
ProductService.vb
Public Class ProductService
Implements IProductServicePublic Function GetWorkOrder(ByVal WorkOrderID As Integer) AsWorkOrder Implements IProductService.GetWorkOrder
Using dc As New LAIT.Model.LAITEntities Try Dim _Order = (From o In dc.WorkOrder Where o.WorkOrderID = WorkOrderID Select o).SingleOrDefault Return _Order Catch ex As Exception Return Nothing End Try End Using End FunctionEnd Class
IProductService.vb
Public Interface IProductService
<OperationContract()> Function GetWorkOrder(ByVal WorkOrderID As Integer) AsLAIT.Entities.WorkOrder
End Interface
The POCO proxy type cannot be directly serialized or deserialized by the Windows Communication Foundation (WCF), because the DataContractSerializer serialization engine can only serialize and deserialize known types. The proxy type is not a known type.
If your POCO entities don’t have any “Navigation Properties” you can have serialized objects of your entities through WCF Services by adding
<DataContract> and <DataMember>properties in your class.But for Entities with “Navigation Properties” In addition of adding
<DataContract> and <DataMember>properties in your class you need to have some changes in your WCF Service as follows. Add the following calss in your WCF Service project.1.
2.Open the service interface file. By default, it is called IService1.
3.Replace the code that defines the service interface file with the following code:
And you are ready to go.