Circular References and WCF

后端 未结 3 1074
挽巷
挽巷 2021-01-12 21:21

I have generated my POCO entities using POCO Generator, I have more than 150+ tables in my database. I am sharing POCO entities all across the application layers including t

3条回答
  •  旧时难觅i
    2021-01-12 21:47

    You already mentioned the approach, but I use this attribute

    public class ReferencePreservingDataContractFormatAttribute : Attribute, IOperationBehavior
        {
            #region IOperationBehavior Members
            public void AddBindingParameters(OperationDescription description, BindingParameterCollection parameters)
            {
            }
    
            public void ApplyClientBehavior(OperationDescription description, System.ServiceModel.Dispatcher.ClientOperation proxy)
            {
                IOperationBehavior innerBehavior = new ReferencePreservingDataContractSerializerOperationBehavior(description);
                innerBehavior.ApplyClientBehavior(description, proxy);
            }
    
            public void ApplyDispatchBehavior(OperationDescription description, System.ServiceModel.Dispatcher.DispatchOperation dispatch)
            {
                IOperationBehavior innerBehavior = new ReferencePreservingDataContractSerializerOperationBehavior(description);
                innerBehavior.ApplyDispatchBehavior(description, dispatch);
            }
    
    
            public void Validate(OperationDescription description)
            {
            }
        #endregion
    }
    

    } ...and reference on an operation on the Service like so;

    [OperationContract]
    [ReferencePreservingDataContractFormat]
    IList Search(string searchString);
    

    FYI - would like to give credit where it's due, but did not record where I originally saw the above approach.

    Edit:

    I believe source of the code is from this blog post.

提交回复
热议问题