惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
O
OpenAI News
W
WeLiveSecurity
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Troy Hunt's Blog
L
LINUX DO - 最新话题
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
H
Heimdal Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Palo Alto Networks Blog
Project Zero
Project Zero
Attack and Defense Labs
Attack and Defense Labs
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Tor Project blog
Scott Helme
Scott Helme
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
Spread Privacy
Spread Privacy
Cisco Talos Blog
Cisco Talos Blog
T
Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
Google DeepMind News
Google DeepMind News
P
Privacy & Cybersecurity Law Blog
Know Your Adversary
Know Your Adversary
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
Lohrmann on Cybersecurity
Cloudbric
Cloudbric
I
Intezer
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
AI
AI
B
Blog
S
Securelist
P
Proofpoint News Feed
量子位
Jina AI
Jina AI
V2EX - 技术
V2EX - 技术
T
The Exploit Database - CXSecurity.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
CERT Recently Published Vulnerability Notes
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 牟向阳

Implementing SQL Server Row and Cell Level Security Daily English 你知道你的後照鏡調錯了嗎?原來裡面隱藏著視線死角! Silverlight Freezing & Crash Silverlight 中实现Service同步调用 Silverlight:获取ContentTemplate中的命名控件 silverlight 4常用的多线程技术 推荐几款Silverlight Tools【转载】 一个配置文件的Mapping Emit Vs CodeDom SQL Service查询分析 WPF&Silverlight精髓 支持定位当前页,自定义排序的分页SQL(拒绝动态SQL) WCF学习经验分享,如何更好地学习WCF? 后台管理界面收集 两个使用的Ajax Demo 自学面向对象 发几个有价值的.net源码 我是如何带领团队开发项目的
Custom DataContractSerializerOperationBehavior
牟向阳 · 2011-01-20 · via 博客园 - 牟向阳

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; 
     
} 
   
}