zoukankan      html  css  js  c++  java
  • Custom DataContractSerializerOperationBehavior

    public class MySerializerFormatAttribute : Attribute, IOperationBehavior 
       
    { 
         
    public void AddBindingParameters(OperationDescription description, BindingParameterCollection parameters) 
         
    { 
         
    } 
     
         
    public void Validate(OperationDescription description) 
         
    { 
         
    } 
     
         
    private static void ReplaceBehavior(OperationDescription description) 
         
    { 
             
    DataContractSerializerOperationBehavior dcsOperationBehavior = description.Behaviors.Find<DataContractSerializerOperationBehavior>(); 
             
    if (dcsOperationBehavior != null) 
             
    { 
               
    int idx = description.Behaviors.IndexOf(dcsOperationBehavior); 
                description
    .Behaviors.Remove(dcsOperationBehavior); 
                description
    .Behaviors.Insert(idx, new MyBehavior(description)); 
             
    } 
         
    } 
     
         
    public void ApplyClientBehavior(OperationDescription description, ClientOperation proxy) 
         
    { 
             
    ReplaceBehavior(description); 
         
    } 
     
     
         
    public void ApplyDispatchBehavior(OperationDescription description, DispatchOperation dispatch) 
         
    { 
             
    ReplaceBehavior(description); 
         
    } 
       
    }; 
     
       
    public class MySerializer : XmlObjectSerializer 
       
    { 
         
    public override bool IsStartObject(XmlDictionaryReader reader) 
         
    { 
             
    throw new NotImplementedException(); 
         
    } 
     
         
    public override object ReadObject(XmlDictionaryReader reader, bool verifyObjectName) 
         
    { 
             
    throw new NotImplementedException(); 
         
    } 
     
         
    public override void WriteEndObject(XmlDictionaryWriter writer) 
         
    { 
             
    throw new NotImplementedException(); 
         
    } 
     
         
    public override void WriteObjectContent(XmlDictionaryWriter writer, object graph) 
         
    { 
             
    throw new NotImplementedException(); 
         
    } 
     
         
    public override void WriteStartObject(XmlDictionaryWriter writer, object graph) 
         
    { 
             
    throw new NotImplementedException(); 
         
    } 
       
    } 
     
       
    // Custom Web service behaviour that passes custom serializer 
       
    public class MyBehavior : DataContractSerializerOperationBehavior 
       
    { 
         
    private static MySerializer serializer = new MySerializer(); 
     
         
    public MyBehavior(OperationDescription operationDescription) : base(operationDescription)  
         
    {  
         
    } 
     
         
    public override XmlObjectSerializer CreateSerializer(Type type, string name, string ns, IList<Type> knownTypes) 
         
    { 
             
    return MyBehavior.serializer; 
         
    } 
     
         
    public override XmlObjectSerializer CreateSerializer(Type type, XmlDictionaryString name, XmlDictionaryString ns, IList<Type> knownTypes) 
         
    { 
             
    return MyBehavior.serializer; 
         
    } 
       
    } 

  • 相关阅读:
    如何使用pip安装PythonMySQLdb模块?
    Linux:信号(1):signal函数、pause函数、alarm函数
    python字符串前面加上'r'的作用
    在LINUX中 用Ctrl+z挂起的命令怎么切回到原任务的命令窗口
    A*寻路初探 GameDev.net
    [3d跑酷] Xcode5 打包 发布配置
    [cb]NGUI组件基类之 UIWidget
    [cb]Unity 项目架构
    使用Unity3D的50个技巧:Unity3D最佳实践
    Doxygen Tool For Unity
  • 原文地址:https://www.cnblogs.com/mxy1028/p/1940342.html
Copyright © 2011-2022 走看看