Basically, this is a serialization issue. I had this problem in my code in the past, but some time has passed, so bear with me.
First we need to find out if the object relations are null before calling WCF, so send debug information before and after.
If the object is returned as null before the call, you have several options:
You can explicitly use .Include ("AnotherObject") in your DbContext to get the object. I used this when my Read method accepted an array of strings into which I used all the necessary objects. This is more convenient than automatically taking all objects, because during serialization, if you take everything, you can pretty easily complete your entire database, which will be serialized, which, among other things, will add performance and security concerns.
Another option is to use a dynamic proxy by adding the virtual keyword in front of your list. However, in DataContractSerializer there is a problem with serializing dynamic proxies, so you will need to implement an attribute that uses ProxyDataContractResolver instead of DataContractResolver. This attribute should apply to all OperationContracts that can transmit dynamic proxies. This will automatically accept ALL object references, which is probably a bad coding practice, so I recommend this method.
public class ApplyDataContractResolverAttribute : Attribute, IOperationBehavior { public ApplyDataContractResolverAttribute() { } public void AddBindingParameters(OperationDescription description, BindingParameterCollection parameters) { } public void ApplyClientBehavior(OperationDescription description, System.ServiceModel.Dispatcher.ClientOperation proxy) { DataContractSerializerOperationBehavior dataContractSerializerOperationBehavior = description.Behaviors.Find<DataContractSerializerOperationBehavior>(); dataContractSerializerOperationBehavior.DataContractResolver = new ProxyDataContractResolver(); } public void ApplyDispatchBehavior(OperationDescription description, System.ServiceModel.Dispatcher.DispatchOperation dispatch) { DataContractSerializerOperationBehavior dataContractSerializerOperationBehavior = description.Behaviors.Find<DataContractSerializerOperationBehavior>(); dataContractSerializerOperationBehavior.DataContractResolver = new ProxyDataContractResolver(); } public void Validate(OperationDescription description) { } }
Edit: I also think that your setters in the Data Contracts may not be public, because I do this and it works fine :). But first, I'll try to make your setter open, and then solve the problem, and then return to the secure network device so that you deal with as few variables as possible at a time.
source share