且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

循环引用和WCF

更新时间:2023-01-17 16:34:54

您已经提到过这种方法,但我用这个属性。

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<SomeObject> Search(string searchString);

仅供参考 - 想给​​信贷,这是由于,但没有记录,我原来看到上面的方法

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

编辑:

我相信的code源来自该博客文章

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