﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-逸天阁</title><link>http://www.cnblogs.com/kriss/</link><description>击长空、博千里，笑慑鬼魅，坦荡万象。四海皆是可有作为，宇内必有余之归宿。</description><language>zh-cn</language><lastBuildDate>Mon, 06 Jul 2009 01:45:08 GMT</lastBuildDate><pubDate>Mon, 06 Jul 2009 01:45:08 GMT</pubDate><ttl>60</ttl><item><title>绕开 CoreLab.MySql 验证</title><link>http://www.cnblogs.com/kriss/archive/2008/10/16/1312889.html</link><dc:creator>逸天</dc:creator><author>逸天</author><pubDate>Thu, 16 Oct 2008 10:10:00 GMT</pubDate><guid>http://www.cnblogs.com/kriss/archive/2008/10/16/1312889.html</guid><wfw:comment>http://www.cnblogs.com/kriss/comments/1312889.html</wfw:comment><comments>http://www.cnblogs.com/kriss/archive/2008/10/16/1312889.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/kriss/comments/commentRss/1312889.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/kriss/services/trackbacks/1312889.html</trackback:ping><description><![CDATA[<p>随着微软在.NET 3.5 SP1中正式推出Entity Framework，很多数据访问提供者开始支持这一新框架。本文涉及到的 Devart MyDirect.NET 就是目前MySql数据库领域支持EF的数据访问组件(MySql Connector据说要等本月底才推出支持EF的新版本)。MyDirect.NET对EF提供了很好的支持，不过免费版只能试用1个月。以下从技术角度阐述如何绕开其验证，仅供学习研究之用。<br />
<br />
1、寻找验证相关的入口函数：</p>
<p>&nbsp;&nbsp;&nbsp; 当到期时，异常信息和调用堆栈如下：<br />
&nbsp; &nbsp; ----&gt; CoreLab.MySql.MySqlException : Sorry, your trial period has expired.<br />
&nbsp;&nbsp;&nbsp; --MySqlException<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at CoreLab.MySql.MySqlConnection.Open()&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp; 在打开MySqlConnection出错，用Reflector分析CoreLab.MySql.dll看一下代码：<br />
</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_155042" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_155042').style.display='none'; document.getElementById('Code_Open_Image_155042').style.display='inline'; document.getElementById('Code_Open_Text_155042').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_155042" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_155042').style.display='none'; getElementById('Code_Closed_Image_155042').style.display='inline'; getElementById('Code_Closed_Text_155042').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_155042">Code</span><span id="Code_Open_Text_155042" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">License&nbsp;license&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;ac.a().GetLicense(LicenseManager.CurrentContext,&nbsp;</span><span style="color: #0000ff">typeof</span><span style="color: #000000">(MySqlConnection),&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">,&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">);<br />
<img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /><br />
u&nbsp;u&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;license&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;u;<br />
</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;((u&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;(u.b()&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">))<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">throw</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;MySqlException(</span><span style="color: #000000">-</span><span style="color: #800080">1</span><span style="color: #000000">,&nbsp;u.b());<br />
}<br />
<img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span></span></div>
<p><br />
可以看到，ac这个类实现LicenseProvider用于产生License，而u这个类继承License对象，同时保存更具体的认证信息。<br />
由于混淆过，我们无从知道u这个类每个字段的含义(a,b,c,d,e,f)，这个时候我们需要人为执行一下GetLicense，看里面到底包含什么数据：<br />
<br />
</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_155617" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_155617').style.display='none'; document.getElementById('Code_Open_Image_155617').style.display='inline'; document.getElementById('Code_Open_Text_155617').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_155617" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_155617').style.display='none'; getElementById('Code_Closed_Image_155617').style.display='inline'; getElementById('Code_Closed_Text_155617').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_155617">Code</span><span id="Code_Open_Text_155617" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">Type&nbsp;licenseType&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">typeof</span><span style="color: #000000">(LicenseProvider);<br />
Assembly&nbsp;coreLabMySql&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">typeof</span><span style="color: #000000">(CoreLab.MySql.MySqlConnection).Assembly;<br />
<br />
Type&nbsp;t&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;coreLabMySql.GetType(</span><span style="color: #800000">"</span><span style="color: #800000">CoreLab.Common.ac</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
Type&nbsp;u&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;coreLabMySql.GetType(</span><span style="color: #800000">"</span><span style="color: #800000">CoreLab.Common.u</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
<br />
</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;创建ac对象</span><span style="color: #008000"><br />
</span><span style="color: #000000">var&nbsp;aMethod&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;t.GetMethod(</span><span style="color: #800000">"</span><span style="color: #800000">a</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;BindingFlags.Static&nbsp;</span><span style="color: #000000">|</span><span style="color: #000000">&nbsp;BindingFlags.Public);<br />
var&nbsp;ac&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;aMethod.Invoke(</span><span style="color: #0000ff">null</span><span style="color: #000000">,&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">object</span><span style="color: #000000">[]&nbsp;{&nbsp;});<br />
<br />
</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;模拟调用GetLicense</span><span style="color: #008000"><br />
</span><span style="color: #000000">MySqlConnection&nbsp;conn&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;MySqlConnection();<br />
var&nbsp;getLicense&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;t.GetMethod(</span><span style="color: #800000">"</span><span style="color: #800000">GetLicense</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
var&nbsp;license&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;getLicense.Invoke(ac,&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">object</span><span style="color: #000000">[]&nbsp;{&nbsp;LicenseManager.CurrentContext,&nbsp;</span><span style="color: #0000ff">typeof</span><span style="color: #000000">(MySqlConnection),&nbsp;conn,&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">&nbsp;});<br />
<br />
</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;查看返回的license</span><span style="color: #008000"><br />
</span><span style="color: #000000">var&nbsp;uLicense&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Convert.ChangeType(license,&nbsp;u);</span></span></div>
<p><br />
调试的时候我们可以看到，u.a包含了LicenseString, u.c则包含了认证失败的错误信息，u.e=3，这个貌似是返回码。<br />
我们把系统时间调前，看一下未到期的时候，产生的license是什么样子：<br />
u.a=LicenseString, u.c=null, u.e=0<br />
<br />
2、产生可以使用的License<br />
</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_160044" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_160044').style.display='none'; document.getElementById('Code_Open_Image_160044').style.display='inline'; document.getElementById('Code_Open_Text_160044').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_160044" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_160044').style.display='none'; getElementById('Code_Closed_Image_160044').style.display='inline'; getElementById('Code_Closed_Text_160044').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_160044">Code</span><span id="Code_Open_Text_160044" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;MyLicenseProvider&nbsp;:&nbsp;LicenseProvider<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">override</span><span style="color: #000000">&nbsp;License&nbsp;GetLicense(LicenseContext&nbsp;context,&nbsp;Type&nbsp;type,&nbsp;</span><span style="color: #0000ff">object</span><span style="color: #000000">&nbsp;instance,&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;allowExceptions)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Assembly&nbsp;coreLabMySql&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">typeof</span><span style="color: #000000">(CoreLab.MySql.MySqlConnection).GetType().Assembly;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type&nbsp;uType&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;coreLabMySql.GetType(</span><span style="color: #800000">"</span><span style="color: #800000">CoreLab.Common.u</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">object</span><span style="color: #000000">&nbsp;u&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Activator.CreateInstance(uType,&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">Here&nbsp;is&nbsp;license&nbsp;string</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">,&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">,&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">,&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;u&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;License;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</span></span></div>
<p><br />
自己运行一下，OK，可以产生一个正常的license<br />
<br />
3、修改DLL<br />
&nbsp;&nbsp;&nbsp;&nbsp; 首先，将上述MyLicenseProvider编译成一个DLL，我们需要得到上述代码的IL:<br />
&nbsp;&nbsp;&nbsp;&nbsp; ilasm MyLicenseProvider.dll /out=MyLicenseProvider.il<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;找到 GetLicense 方法： <br />
</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_160445" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_160445').style.display='none'; document.getElementById('Code_Open_Image_160445').style.display='inline'; document.getElementById('Code_Open_Text_160445').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_160445" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_160445').style.display='none'; getElementById('Code_Closed_Image_160445').style.display='inline'; getElementById('Code_Closed_Text_160445').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_160445">Code</span><span id="Code_Open_Text_160445" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000">//</span><span style="color: #008000">&nbsp;Code&nbsp;size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;82&nbsp;(0x52)</span><span style="color: #008000"><br />
</span><span style="color: #000000">.maxstack&nbsp;&nbsp;</span><span style="color: #800080">4</span><span style="color: #000000"><br />
.locals&nbsp;init&nbsp;([</span><span style="color: #800080">0</span><span style="color: #000000">]&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;[mscorlib]System.Reflection.Assembly&nbsp;coreLabMySql,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[</span><span style="color: #800080">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;[mscorlib]System.Type&nbsp;uType,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[</span><span style="color: #800080">2</span><span style="color: #000000">]&nbsp;</span><span style="color: #0000ff">object</span><span style="color: #000000">&nbsp;u,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[</span><span style="color: #800080">3</span><span style="color: #000000">]&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;[System]System.ComponentModel.License&nbsp;CS$</span><span style="color: #800080">1</span><span style="color: #000000">$</span><span style="color: #800080">0000</span><span style="color: #000000">,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[</span><span style="color: #800080">4</span><span style="color: #000000">]&nbsp;</span><span style="color: #0000ff">object</span><span style="color: #000000">[]&nbsp;CS$</span><span style="color: #800080">0</span><span style="color: #000000">$</span><span style="color: #800080">0001</span><span style="color: #000000">)<br />
IL_0000:&nbsp;&nbsp;nop<br />
IL_0001:&nbsp;&nbsp;ldarg.</span><span style="color: #800080">0</span><span style="color: #000000"><br />
IL_0002:&nbsp;&nbsp;call&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;[mscorlib]System.Type&nbsp;[mscorlib]System.Object::GetType()<br />
IL_0007:&nbsp;&nbsp;callvirt&nbsp;&nbsp;&nbsp;instance&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;[mscorlib]System.Reflection.Assembly&nbsp;[mscorlib]System.Type::get_Assembly()<br />
IL_000c:&nbsp;&nbsp;stloc.</span><span style="color: #800080">0</span><span style="color: #000000"><br />
IL_000d:&nbsp;&nbsp;ldloc.</span><span style="color: #800080">0</span><span style="color: #000000"><br />
IL_000e:&nbsp;&nbsp;ldstr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">CoreLab.Common.u</span><span style="color: #800000">"</span><span style="color: #000000"><br />
IL_0013:&nbsp;&nbsp;callvirt&nbsp;&nbsp;&nbsp;instance&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;[mscorlib]System.Type&nbsp;[mscorlib]System.Reflection.Assembly::GetType(</span><span style="color: #0000ff">string</span><span style="color: #000000">)<br />
IL_0018:&nbsp;&nbsp;stloc.</span><span style="color: #800080">1</span><span style="color: #000000"><br />
IL_0019:&nbsp;&nbsp;ldloc.</span><span style="color: #800080">1</span><span style="color: #000000"><br />
IL_001a:&nbsp;&nbsp;ldc.i4.</span><span style="color: #800080">5</span><span style="color: #000000"><br />
IL_001b:&nbsp;&nbsp;newarr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[mscorlib]System.Object<br />
IL_0020:&nbsp;&nbsp;stloc.s&nbsp;&nbsp;&nbsp;&nbsp;CS$</span><span style="color: #800080">0</span><span style="color: #000000">$</span><span style="color: #800080">0001</span><span style="color: #000000"><br />
IL_0022:&nbsp;&nbsp;ldloc.s&nbsp;&nbsp;&nbsp;&nbsp;CS$</span><span style="color: #800080">0</span><span style="color: #000000">$</span><span style="color: #800080">0001</span><span style="color: #000000"><br />
IL_0024:&nbsp;&nbsp;ldc.i4.</span><span style="color: #800080">0</span><span style="color: #000000"><br />
IL_0025:&nbsp;&nbsp;ldstr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">here&nbsp;is&nbsp;license&nbsp;string</span><span style="color: #800000">"</span><span style="color: #000000"><br />
</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">k0WXphh/g4KEcX</span><span style="color: #800000">"</span><span style="color: #000000"><br />
IL_002a:&nbsp;&nbsp;stelem.</span><span style="color: #0000ff">ref</span><span style="color: #000000"><br />
IL_002b:&nbsp;&nbsp;ldloc.s&nbsp;&nbsp;&nbsp;&nbsp;CS$</span><span style="color: #800080">0</span><span style="color: #000000">$</span><span style="color: #800080">0001</span><span style="color: #000000"><br />
IL_002d:&nbsp;&nbsp;ldc.i4.</span><span style="color: #800080">2</span><span style="color: #000000"><br />
IL_002e:&nbsp;&nbsp;ldc.i4.</span><span style="color: #800080">0</span><span style="color: #000000"><br />
IL_002f:&nbsp;&nbsp;box&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[mscorlib]System.Boolean<br />
IL_0034:&nbsp;&nbsp;stelem.</span><span style="color: #0000ff">ref</span><span style="color: #000000"><br />
IL_0035:&nbsp;&nbsp;ldloc.s&nbsp;&nbsp;&nbsp;&nbsp;CS$</span><span style="color: #800080">0</span><span style="color: #000000">$</span><span style="color: #800080">0001</span><span style="color: #000000"><br />
IL_0037:&nbsp;&nbsp;ldc.i4.</span><span style="color: #800080">3</span><span style="color: #000000"><br />
IL_0038:&nbsp;&nbsp;ldc.i4.</span><span style="color: #800080">0</span><span style="color: #000000"><br />
IL_0039:&nbsp;&nbsp;box&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[mscorlib]System.Int32<br />
IL_003e:&nbsp;&nbsp;stelem.</span><span style="color: #0000ff">ref</span><span style="color: #000000"><br />
IL_003f:&nbsp;&nbsp;ldloc.s&nbsp;&nbsp;&nbsp;&nbsp;CS$</span><span style="color: #800080">0</span><span style="color: #000000">$</span><span style="color: #800080">0001</span><span style="color: #000000"><br />
IL_0041:&nbsp;&nbsp;call&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">object</span><span style="color: #000000">&nbsp;[mscorlib]System.Activator::CreateInstance(</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;[mscorlib]System.Type,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">object</span><span style="color: #000000">[])<br />
IL_0046:&nbsp;&nbsp;stloc.</span><span style="color: #800080">2</span><span style="color: #000000"><br />
IL_0047:&nbsp;&nbsp;ldloc.</span><span style="color: #800080">2</span><span style="color: #000000"><br />
IL_0048:&nbsp;&nbsp;isinst&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[System]System.ComponentModel.License<br />
IL_004d:&nbsp;&nbsp;stloc.</span><span style="color: #800080">3</span><span style="color: #000000"><br />
IL_004e:&nbsp;&nbsp;br.s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IL_0050<br />
<br />
IL_0050:&nbsp;&nbsp;ldloc.</span><span style="color: #800080">3</span><span style="color: #000000"><br />
IL_0051:&nbsp;&nbsp;ret<br />
</span></span></div>
<p><br />
接下来我们要反汇编 CoreLab.MySql.dll<br />
运行 ildasm CoreLab.MySql.dll /out=source.il<br />
这时出现提示信息 "Protected Module"，无法反汇编。这是因为这个动态库增加了SuppressIldasmAttribute属性，从而ildasm不允许反汇编。我们可以很容易制造一个hack过的ildasm.exe版本，方法如下：<br />
用二进制编辑器(如WinHex)打开C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\ildasm.exe<br />
查找SuppressIldasmAttribute，将其修改为任意字符串，保存。<br />
<br />
现在重新执行ildasm CoreLab.MySql.dll /out=source.il，得到CoreLab.MySql的il代码，查找以下代码： <br />
</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_165528" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_165528').style.display='none'; document.getElementById('Code_Open_Image_165528').style.display='inline'; document.getElementById('Code_Open_Text_165528').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_165528" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_165528').style.display='none'; getElementById('Code_Closed_Image_165528').style.display='inline'; getElementById('Code_Closed_Text_165528').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_165528">Code</span><span id="Code_Open_Text_165528" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">&nbsp;&nbsp;.method&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;hidebysig&nbsp;</span><span style="color: #0000ff">virtual</span><span style="color: #000000">&nbsp;instance&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;[System]System.ComponentModel.License&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a(</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;[System]System.ComponentModel.LicenseContext&nbsp;A_0,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;[mscorlib]System.Type&nbsp;A_1,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">object</span><span style="color: #000000">&nbsp;A_2,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;A_3)&nbsp;cil&nbsp;managed</span></span></div>
<br />
用我们之前得到的MyLicenseProvider里面的il代码替换a()方法，注意保留第一行的.override [System]System.ComponentModel.LicenseProvider::GetLicense<br />
<br />
我们在重新编译il之前，还有一些工作要做，其中最重要的就是产生强名称签名。没有强名称签名，这个修改过的dll是无法工作的。<br />
<br />
4、产生和修改强名称<br />
&nbsp;&nbsp;&nbsp; 首先产生一对key:<br />
&nbsp;&nbsp;&nbsp; sn -k key.snk<br />
&nbsp;&nbsp;&nbsp; 然后从中提取公钥<br />
&nbsp;&nbsp;&nbsp; sn -p key.snk public.key<br />
&nbsp;&nbsp;&nbsp; 然后显示PublicKeyToken<br />
&nbsp;&nbsp;&nbsp; sn -t public.key<br />
&nbsp;&nbsp;&nbsp; 这个时候会显示Public key token is a603cb3085449c2c<br />
&nbsp;&nbsp;&nbsp; 这个public key token要记下来，我们下面要用到<br />
<br />
&nbsp;&nbsp;&nbsp; 这里需要说明一下CoreLab.MySql.dll和CoreLab.MySql.Entity.dll的关系。<br />
&nbsp;&nbsp;&nbsp; 从名称上可以看出，CoreLab.MySql.Entity.dll用于支持Entity Framework，所以其必然会引用强名称版本的CoreLab.MySql.dll，通过Reflector查看Reference可以验证我们的猜想。按照我们的思路，修改CoreLab.MySql.dll的验证部分代码，然后用我们产生的新的key去签名，为了支持EF，有必要同时产生一个配套的修改版CoreLab.MySql.Entity.dll。<br />
<br />
&nbsp;&nbsp;&nbsp; 回头看CoreLab.MySql.dll，我们使用EF也好，使用ADO.NET也好，其Data Provider都是指向CoreLab.MySql。通过反射可知，这些功能都是由 CoreLab.MySql.MySqlDirectFactory工厂来支持的，这个类实现了接口DbProviderFactory和IServiceProvider，前者用于支持ADO.NET Data Provider，后者用于支持Entity Framework。我们看到MySqlDirectFactory里有如下方法签名：private object a(Type A_0); 这个方法便实现了IServiceProvider.GetService(Type serviceType)方法。在它的实现里，可以看到如下代码：
<div class="cnblogs_code"><img id="Code_Closed_Image_174043" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_174043').style.display='none'; document.getElementById('Code_Open_Image_174043').style.display='inline'; document.getElementById('Code_Open_Text_174043').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_174043" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_174043').style.display='none'; getElementById('Code_Closed_Image_174043').style.display='inline'; getElementById('Code_Closed_Text_174043').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_174043">Code</span><span id="Code_Open_Text_174043" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">&nbsp;&nbsp;Type&nbsp;type&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(a&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">?</span><span style="color: #000000">&nbsp;Type.GetType(</span><span style="color: #800000">"</span><span style="color: #800000">CoreLab.MySql.Entity.MySqlEntityProviderServices,&nbsp;CoreLab.MySql.Entity,&nbsp;Version=4.85.35.0,&nbsp;Culture=neutral,&nbsp;PublicKeyToken=09af7300eec23701</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">)&nbsp;:&nbsp;a.GetType();<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(type&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Assembly&nbsp;assembly&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Assembly.Load(</span><span style="color: #800000">"</span><span style="color: #800000">CoreLab.MySql.Entity,&nbsp;Version=4.85.35.0,&nbsp;Culture=neutral,&nbsp;PublicKeyToken=09af7300eec23701</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(assembly&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;assembly.GetType(</span><span style="color: #800000">"</span><span style="color: #800000">CoreLab.MySql.Entity.MySqlEntityProviderServices</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span></span></div>
<p><br />
把这里的PublicKeyToken=09af7300eec23701替换成我们刚才自己产生的KeyToken, a603cb3085449c2c。<br />
<br />
好了，现在可以重新编译 CoreLab.MySql.dll 了，运行以下命令：<br />
ilasm source.il /dll /key=key.snk /out=CoreLab.MySql.dll<br />
<br />
接下来我们修改CoreLab.MySql.Entity.dll对CoreLab.MySql.dll的引用。<br />
&nbsp;&nbsp;1) 反汇编IL<br />
&nbsp;&nbsp;&nbsp;ildasm&nbsp;CoreLab.MySql.Entity.dll /out=entity_source.il<br />
&nbsp; 2)&nbsp;查找 .assembly extern CoreLab.MySql<br />
&nbsp;&nbsp;&nbsp;将publickeytoken改成上面产生的新key，每个字节用空格隔开<br />
&nbsp;&nbsp;3) 重新编译<br />
&nbsp;&nbsp; ilasm entity_source.il /dll /key=key.snk /out=CoreLab.MySql.Entity.dll<br />
<br />
对DLL和强名称的修改完成后，我们可以重新注册这些DLL并且使用了。<br />
<br />
5、注册GAC<br />
&nbsp;&nbsp;&nbsp;&nbsp; gacutil /i CoreLab.MySql.dll<br />
&nbsp;&nbsp;&nbsp;&nbsp; gacutil /i CoreLab.MySql.Entity.dll<br />
&nbsp;&nbsp;&nbsp;&nbsp; 如果打开C:\Windows\Assembly，我们现在应该可以看到两个版本的DLL，一个是原始版，一个是修改版<br />
<br />
6、最后一步，修改machine.config使用修改版Data Provider.<br />
&nbsp;&nbsp;&nbsp; 编辑 C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config<br />
&nbsp;&nbsp;&nbsp; 找到以下这一段配置：<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;add name="MyDirect .NET" invariant="CoreLab.MySql" description="CoreLab MyDirect .NET"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type="CoreLab.MySql.MySqlDirectFactory, CoreLab.MySql, Version=4.85.35.0, Culture=neutral, PublicKeyToken=09af7300eec23701" /&gt;<br />
&nbsp;&nbsp; 将PublicKeyToken改成我们的key<br />
<br />
大功告成~!</p>
<img src ="http://www.cnblogs.com/kriss/aggbug/1312889.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47995/" target="_blank">Google Voice 上手</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>纪念南京大屠杀70周年</title><link>http://www.cnblogs.com/kriss/archive/2007/12/13/993550.html</link><dc:creator>逸天</dc:creator><author>逸天</author><pubDate>Thu, 13 Dec 2007 05:13:00 GMT</pubDate><guid>http://www.cnblogs.com/kriss/archive/2007/12/13/993550.html</guid><wfw:comment>http://www.cnblogs.com/kriss/comments/993550.html</wfw:comment><comments>http://www.cnblogs.com/kriss/archive/2007/12/13/993550.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/kriss/comments/commentRss/993550.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/kriss/services/trackbacks/993550.html</trackback:ping><description><![CDATA[<img height="100" alt="" src="http://www.cnblogs.com/images/cnblogs_com/kriss/U1010P1T63D3406F1724DT20071212140222.jpg" width="750" border="0" />
<img src ="http://www.cnblogs.com/kriss/aggbug/993550.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47994/" target="_blank">Google号召社区力量为互联网加速</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>如何通过活动目录(ADSI)修改IIS6中的 Web 服务扩展</title><link>http://www.cnblogs.com/kriss/archive/2006/03/03/342467.html</link><dc:creator>逸天</dc:creator><author>逸天</author><pubDate>Fri, 03 Mar 2006 15:11:00 GMT</pubDate><guid>http://www.cnblogs.com/kriss/archive/2006/03/03/342467.html</guid><wfw:comment>http://www.cnblogs.com/kriss/comments/342467.html</wfw:comment><comments>http://www.cnblogs.com/kriss/archive/2006/03/03/342467.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/kriss/comments/commentRss/342467.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/kriss/services/trackbacks/342467.html</trackback:ping><description><![CDATA[摘要: &nbsp;&nbsp;<a href='http://www.cnblogs.com/kriss/archive/2006/03/03/342467.html'>阅读全文</a><img src ="http://www.cnblogs.com/kriss/aggbug/342467.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47989/" target="_blank">Twitter无处不在 魔兽世界Twitter发送器插件发布</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>XMLDOM/XMLHTTP的跨域访问和页面代理</title><link>http://www.cnblogs.com/kriss/archive/2006/03/03/342445.html</link><dc:creator>逸天</dc:creator><author>逸天</author><pubDate>Fri, 03 Mar 2006 14:44:00 GMT</pubDate><guid>http://www.cnblogs.com/kriss/archive/2006/03/03/342445.html</guid><wfw:comment>http://www.cnblogs.com/kriss/comments/342445.html</wfw:comment><comments>http://www.cnblogs.com/kriss/archive/2006/03/03/342445.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cnblogs.com/kriss/comments/commentRss/342445.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/kriss/services/trackbacks/342445.html</trackback:ping><description><![CDATA[摘要: &nbsp;&nbsp;<a href='http://www.cnblogs.com/kriss/archive/2006/03/03/342445.html'>阅读全文</a><img src ="http://www.cnblogs.com/kriss/aggbug/342445.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47989/" target="_blank">Twitter无处不在 魔兽世界Twitter发送器插件发布</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>关于如何让页面同时下载多个文件的尝试</title><link>http://www.cnblogs.com/kriss/archive/2006/02/23/335885.html</link><dc:creator>逸天</dc:creator><author>逸天</author><pubDate>Wed, 22 Feb 2006 18:30:00 GMT</pubDate><guid>http://www.cnblogs.com/kriss/archive/2006/02/23/335885.html</guid><wfw:comment>http://www.cnblogs.com/kriss/comments/335885.html</wfw:comment><comments>http://www.cnblogs.com/kriss/archive/2006/02/23/335885.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cnblogs.com/kriss/comments/commentRss/335885.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/kriss/services/trackbacks/335885.html</trackback:ping><description><![CDATA[摘要: &nbsp;&nbsp;<a href='http://www.cnblogs.com/kriss/archive/2006/02/23/335885.html'>阅读全文</a><img src ="http://www.cnblogs.com/kriss/aggbug/335885.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47988/" target="_blank">Firefox 3.5匆忙推出漏洞多 Mozilla本月将更新</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>纪念南京大屠杀68周年，牢记历史</title><link>http://www.cnblogs.com/kriss/archive/2005/12/12/295861.html</link><dc:creator>逸天</dc:creator><author>逸天</author><pubDate>Mon, 12 Dec 2005 15:36:00 GMT</pubDate><guid>http://www.cnblogs.com/kriss/archive/2005/12/12/295861.html</guid><wfw:comment>http://www.cnblogs.com/kriss/comments/295861.html</wfw:comment><comments>http://www.cnblogs.com/kriss/archive/2005/12/12/295861.html#Feedback</comments><slash:comments>38</slash:comments><wfw:commentRss>http://www.cnblogs.com/kriss/comments/commentRss/295861.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/kriss/services/trackbacks/295861.html</trackback:ping><description><![CDATA[<STRONG style="FONT-SIZE: 36pt">1937</STRONG><SPAN style="FONT-SIZE: 18pt">年</SPAN><STRONG style="FONT-SIZE: 36pt">12</STRONG><SPAN style="FONT-SIZE: 18pt">月</SPAN><STRONG style="FONT-SIZE: 36pt">13</STRONG><SPAN style="FONT-SIZE: 18pt">日</SPAN>，侵华日军攻入民国首都南京，随后进行了惨绝人寰的大屠杀。<BR><BR><IMG height=327 alt=纪念南京大屠杀68周年 hspace=0 src="http://www.cnblogs.com/images/cnblogs_com/kriss/Nanjing.JPG" width=729><BR>首页上放一天，与大家共勉。条件允许的，希望有机会能够去南京看一下。前事不忘，后事之师。 <img src ="http://www.cnblogs.com/kriss/aggbug/295861.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47987/" target="_blank">预测：Twitter最可能收购的十家公司</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>Remoting中的线程与网络通信内幕初探</title><link>http://www.cnblogs.com/kriss/archive/2005/12/02/288900.html</link><dc:creator>逸天</dc:creator><author>逸天</author><pubDate>Thu, 01 Dec 2005 19:15:00 GMT</pubDate><guid>http://www.cnblogs.com/kriss/archive/2005/12/02/288900.html</guid><wfw:comment>http://www.cnblogs.com/kriss/comments/288900.html</wfw:comment><comments>http://www.cnblogs.com/kriss/archive/2005/12/02/288900.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.cnblogs.com/kriss/comments/commentRss/288900.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/kriss/services/trackbacks/288900.html</trackback:ping><description><![CDATA[<P>　　<SPAN style="FONT-SIZE: 18pt">在</SPAN>使用Remoting之前一直很关心它的并发处理能力。之前写了一个小测试，两个Client线程访问远程对象，一个应该是立即返回，另外一个应该是线程休眠3秒钟后返回。结果发现两个线程的远程调用都是在3秒后返回。 <BR>　　今天在翻阅MSDN中关于Remoting的章节时，发现有以下一些记载： <BR>　　<U>[使用 .NET Framework 编程 -&gt; .NET 远程处理概述 -&gt; 信道 -&gt; 信道规则] <BR></U>　　<U>远程对象共享信道；远程对象不拥有信道。</U> <BR>　　<U>由于每个客户端连接都是在它自己的线程中处理的，因此单个信道可以同时服务于多个客户端。 <BR><BR></U>　　照这段话的描述来看，服务端为每一个客户端连接都分配一个独立线程进行处理，那么，Remoting服务端应该是支持并发处理的，不太可能因为线程阻塞造成两个线程都是3秒以后返回。 <BR>　　于是今天配合SockMon 2005，把Remoting调用中的端口和网络使用情况进行了跟踪，发现我是被最初的那个测试误导了。通过跟踪，也了解了一些Remoting的具体实现细节，我以前困惑的一些问题，比如网络连接何时创建，何时销毁，等等问题，也都有了答案。 <BR><BR>　　首先我们看一下我的那个测试程序： <BR>　　这是远程对象，在i为奇数的时候，线程休眠3秒后返回，否则立即返回。 <BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG id=Codehighlighter1_44_312_Open_Image onclick="this.style.display='none'; Codehighlighter1_44_312_Open_Text.style.display='none'; Codehighlighter1_44_312_Closed_Image.style.display='inline'; Codehighlighter1_44_312_Closed_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" width=11 align=top><IMG id=Codehighlighter1_44_312_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_44_312_Closed_Text.style.display='none'; Codehighlighter1_44_312_Open_Image.style.display='inline'; Codehighlighter1_44_312_Open_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" width=11 align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;TestClass&nbsp;:&nbsp;MarshalByRefObject&nbsp;</SPAN><SPAN id=Codehighlighter1_44_312_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG height=20 src="http://www.cnblogs.com/Images/dot.gif" width=15></SPAN><SPAN id=Codehighlighter1_44_312_Open_Text><SPAN style="COLOR: #000000">{&nbsp; <BR><IMG id=Codehighlighter1_77_309_Open_Image onclick="this.style.display='none'; Codehighlighter1_77_309_Open_Text.style.display='none'; Codehighlighter1_77_309_Closed_Image.style.display='inline'; Codehighlighter1_77_309_Closed_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" width=11 align=top><IMG id=Codehighlighter1_77_309_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_77_309_Closed_Text.style.display='none'; Codehighlighter1_77_309_Open_Image.style.display='inline'; Codehighlighter1_77_309_Open_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;Call(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i)&nbsp;</SPAN><SPAN id=Codehighlighter1_77_309_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG height=20 src="http://www.cnblogs.com/Images/dot.gif" width=15></SPAN><SPAN id=Codehighlighter1_77_309_Open_Text><SPAN style="COLOR: #000000">{&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">long</SPAN><SPAN style="COLOR: #000000">&nbsp;t1&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;DateTime.Now.Ticks;&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">%</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">&nbsp;)&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Threading.Thread.Sleep(&nbsp;</SPAN><SPAN style="COLOR: #000000">3000</SPAN><SPAN style="COLOR: #000000">&nbsp;);&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">long</SPAN><SPAN style="COLOR: #000000">&nbsp;t2&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;DateTime.Now.Ticks;&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">.Format(&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Hello&nbsp;[I={0},T={1}]</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;i,&nbsp;t2&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">&nbsp;t1&nbsp;);&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" width=11 align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN> </DIV>
<P><BR>　　客户端，执行 (new ClientTest ()).Run()： <BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG id=Codehighlighter1_17_506_Open_Image onclick="this.style.display='none'; Codehighlighter1_17_506_Open_Text.style.display='none'; Codehighlighter1_17_506_Closed_Image.style.display='inline'; Codehighlighter1_17_506_Closed_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" width=11 align=top><IMG id=Codehighlighter1_17_506_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_17_506_Closed_Text.style.display='none'; Codehighlighter1_17_506_Open_Image.style.display='inline'; Codehighlighter1_17_506_Open_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" width=11 align=top><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;ClientTest&nbsp;</SPAN><SPAN id=Codehighlighter1_17_506_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG height=20 src="http://www.cnblogs.com/Images/dot.gif" width=15></SPAN><SPAN id=Codehighlighter1_17_506_Open_Text><SPAN style="COLOR: #000000">{&nbsp; <BR><IMG id=Codehighlighter1_42_265_Open_Image onclick="this.style.display='none'; Codehighlighter1_42_265_Open_Text.style.display='none'; Codehighlighter1_42_265_Closed_Image.style.display='inline'; Codehighlighter1_42_265_Closed_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" width=11 align=top><IMG id=Codehighlighter1_42_265_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_42_265_Closed_Text.style.display='none'; Codehighlighter1_42_265_Open_Image.style.display='inline'; Codehighlighter1_42_265_Open_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;Run()&nbsp;</SPAN><SPAN id=Codehighlighter1_42_265_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG height=20 src="http://www.cnblogs.com/Images/dot.gif" width=15></SPAN><SPAN id=Codehighlighter1_42_265_Open_Text><SPAN style="COLOR: #000000">{&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ChannelServices.RegisterChannel(&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;TcpClientChannel()&nbsp;);&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">;&nbsp;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">&nbsp;)&nbsp; <BR><IMG id=Codehighlighter1_160_258_Open_Image onclick="this.style.display='none'; Codehighlighter1_160_258_Open_Text.style.display='none'; Codehighlighter1_160_258_Closed_Image.style.display='inline'; Codehighlighter1_160_258_Closed_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" width=11 align=top><IMG id=Codehighlighter1_160_258_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_160_258_Closed_Text.style.display='none'; Codehighlighter1_160_258_Open_Image.style.display='inline'; Codehighlighter1_160_258_Open_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_160_258_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG height=20 src="http://www.cnblogs.com/Images/dot.gif" width=15></SPAN><SPAN id=Codehighlighter1_160_258_Open_Text><SPAN style="COLOR: #000000">{&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread&nbsp;t&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Thread(&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;ThreadStart(&nbsp;Test&nbsp;)&nbsp;);&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.Start();&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top> <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top> <BR><IMG id=Codehighlighter1_309_503_Open_Image onclick="this.style.display='none'; Codehighlighter1_309_503_Open_Text.style.display='none'; Codehighlighter1_309_503_Closed_Image.style.display='inline'; Codehighlighter1_309_503_Closed_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" width=11 align=top><IMG id=Codehighlighter1_309_503_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_309_503_Closed_Text.style.display='none'; Codehighlighter1_309_503_Open_Image.style.display='inline'; Codehighlighter1_309_503_Open_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;Test()&nbsp;</SPAN><SPAN id=Codehighlighter1_309_503_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG height=20 src="http://www.cnblogs.com/Images/dot.gif" width=15></SPAN><SPAN id=Codehighlighter1_309_503_Open_Text><SPAN style="COLOR: #000000">{&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;t&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">;&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TestClass&nbsp;tc&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(TestClass)&nbsp;Activator.GetObject(&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">typeof</SPAN><SPAN style="COLOR: #000000">(&nbsp;TestClass&nbsp;),&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">tcp://localhost:8086/Test</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;);&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(&nbsp;tc.Call(&nbsp;t&nbsp;)&nbsp;);&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" width=11 align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" width=11 align=top> <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" width=11 align=top></SPAN> </DIV>
<P><BR>　　运行这个测试程序，发现有3种情况： <BR>　　1、正常运行后两个线程几乎都是在3秒以后，返回： <BR>　　　　Hello [I=0, T=0] Hello [I=1, T=30000384] <BR>　　2、用SockMon监视网络的时候，再运行测试程序， <BR>　　　　I=0的消息马上返回，I=1的是3秒以后返回。这个结果应该是正常的。 <BR>　　3、用RemotingConfiguration.Configure( "Client.exe.config" ); 替换掉 <BR>　　　　ChannelServices.RegisterChannel( new TcpClientChannel() ); <BR>　　　　也就是说用配置文件注册通道的时候， <BR>　　　　不管SockMon有没有开启，测试程序的结果也都是正常的，同第2种情况。 <BR><BR>　　这第2和第3两种情况着实让人郁闷，出现测试结果全然不同的原因是什么？服务端到底是怎样处理的？让我们先来看看跟踪数据： <BR><BR>
<TABLE style="BORDER-COLLAPSE: collapse; HEIGHT: 584px" cellSpacing=1 cellPadding=3 align=center bgColor=#660000 border=0>
<TBODY>
<TR bgColor=#ffcc66>
<TD align=middle width=21>No.</TD>
<TD align=middle width=42>对象</TD>
<TD align=middle width=32>线程</TD>
<TD align=middle width=63>Local <BR>Port </TD>
<TD align=middle width=70>Remote <BR>Port </TD>
<TD width=170>操作</TD>
<TD width=132>备注</TD></TR>
<TR bgColor=#e0e0cc>
<TD align=middle>1</TD>
<TD align=middle>Server</TD>
<TD align=middle><STRONG>4584</STRONG> </TD>
<TD align=middle>8086</TD>
<TD align=middle>&nbsp;</TD>
<TD>绑定端口并开始监听</TD>
<TD>发生在信道注册 <BR>ChannelServices <BR>.RegisterChannel </TD></TR>
<TR bgColor=#ffffcc>
<TD align=middle>2</TD>
<TD align=middle>Client</TD>
<TD align=middle>5132</TD>
<TD align=middle>2296</TD>
<TD align=middle>8086</TD>
<TD>连接并发送请求tcp://localhost:8086/Test</TD>
<TD>发生在远程方法调用 <BR>tc.Call( t )，t = 0 </TD></TR>
<TR bgColor=#fff0cc>
<TD align=middle>3</TD>
<TD align=middle>Client</TD>
<TD align=middle>4276</TD>
<TD align=middle>2297</TD>
<TD align=middle>8086</TD>
<TD>连接并发送请求tcp://localhost:8086/Test</TD>
<TD>发生在远程方法调用 <BR>tc.Call( t )，t = 1 </TD></TR>
<TR bgColor=#e0e0cc>
<TD align=middle>4</TD>
<TD align=middle>Server</TD>
<TD align=middle><STRONG>780</STRONG> </TD>
<TD align=middle>8086</TD>
<TD align=middle>2096</TD>
<TD>返回信息 Hello [I=0, T=0]</TD>
<TD>&nbsp;</TD></TR>
<TR bgColor=#ffffcc>
<TD align=middle>5</TD>
<TD align=middle>Client</TD>
<TD align=middle>5132</TD>
<TD align=middle>2296</TD>
<TD align=middle>8086</TD>
<TD>接受到 Hello [I=0, T=0]</TD>
<TD>&nbsp;</TD></TR>
<TR bgColor=#e0e0cc>
<TD align=middle>6</TD>
<TD align=middle>Server</TD>
<TD align=middle><STRONG>780</STRONG> </TD>
<TD align=middle>8086</TD>
<TD align=middle>2096</TD>
<TD>返回信息 <BR>Hello [I=1, T=30000384] </TD>
<TD>&nbsp;</TD></TR>
<TR bgColor=#fff0cc>
<TD align=middle>7</TD>
<TD align=middle>Client</TD>
<TD align=middle>4276</TD>
<TD align=middle>2297</TD>
<TD align=middle>8086</TD>
<TD>接受到 <BR>Hello [I=1, T=30000384] </TD>
<TD>&nbsp;</TD></TR></TBODY></TABLE></P>
<P><BR>　　我们来大致回顾一下这个流程。首先Server端在信道注册(ChannelServices.RegisterChannel)以后，就会立即在指定端口开始监听。然后Client开始创建第一个TestClass。并调用它的远程方法Call()。这时，Client选取一个新的端口(2296)与服务器进行通信请求。然后我们看到第二个线程(ID:4276)里又创建一个TestClass，并在新端口(2297)上连接服务器。 <BR>　　到这一步为止，我们可以看到非常重要的一个事实，就是执行 Activator.GetObject() 时，实际上并没有访问网络。 <BR>　　只有在实际调用远程方法的时候，Remoting才实际开始通过网络通信向服务器请求处理。对于在服务器端激活的SAO对象来说，也正是在这个时候创建远程对象（注：Singleton在全局范围内只创建一个对象实例，SingleCall则为每个客户端创建一个对象实例，所以实际上这个时候并不一定全都是创建新的对象实例） <BR><BR>　　其次，Client在不同的线程当中，使用了不同的端口与服务器通信。也就是说开启了两个网络连接。而在测试代码中，不管是通过配置文件，还是通过代码注册信道，我们实际上都只注册了一个TcpClientChannel。在这一点上还是有些疑问... 另外，对于客户端信道来说，似乎无法指定其端口。每次系统都无视我指定的端口，而自行开启别的端口进行通信 -_- <BR><BR>　　好了，我们从No.4继续。可以看到Server分别处理了Call(0), Call(1)两个调用。而且I=0的时候，中间没有进行线程休眠，所以处理耗时基本为0。但是我注意到，Server在实际处理远程调用时，是用了另外一个线程(ID:780)。也就是说，在Server端，4584线程负责监听，而780线程则另外开辟用来处理客户请求。而且，对于Client在2296和2297两个端口上的请求，Server端用的是同一个线程进行处理！ <BR><BR>　　等等，有没有可能是这样一种情况： <BR>　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　&nbsp;&nbsp; /-----线程A <BR>　　SERVER(4584线程）：监听 ____/----780线程：负责联络ClientA -------\-----线程B <BR>　　　　　　　　　　　　　　　&nbsp; 　　 \----XXX线程：负责联络ClientX------/----线程C <BR>　　　　　　　　　　　　　　　　　　　　　　　　　　　&nbsp;&nbsp;&nbsp; 　　　　　&nbsp;&nbsp;&nbsp; 　\----线程D <BR><BR>　　也就是说主监听线程在接受到不同客户端发来的请求时，开辟新的通信线程与客户进行沟通。而每个通信线程只负责网络层的传输，仍不负责实际的远程处理，而是再开辟新的多线程分配任务的处理呢？似乎有这样的可能，因为这样的好处是实现真正的并发处理。不管客户端是单线程还是多线程，只要有请求过来，都会立即交去处理。 <BR><BR>　　我们把代码稍微改动一下，注释掉 TestClass.Call() 方法里的 // if ( i % 2 == 1 ) ，这样只要调用Call()，结果都会在3秒以后返回。 <BR>　　测试结果，在网络跟踪上与上一次无异。但是两个 Hello 几乎是在3秒以后同时出现。这也就说明了服务端两个Call()方法差不多是同时调用的。但这次客户端的两个请求，在网络层的跟踪看来，仍然是在一个通信线程(780)里进行。这就验证了我在上面的猜想有可能是正确的。因为通过SockMon跟踪到的线程，只是Socket相关的线程，并不能代表所有的线程的使用情况。很可能远程方法是由哪个未知名的线程完成的。 <BR><BR>　　我们再来做今天最后一个测试。同时开两个Client。代码修改如下： <BR><BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG id=Codehighlighter1_44_157_Open_Image onclick="this.style.display='none'; Codehighlighter1_44_157_Open_Text.style.display='none'; Codehighlighter1_44_157_Closed_Image.style.display='inline'; Codehighlighter1_44_157_Closed_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" width=11 align=top><IMG id=Codehighlighter1_44_157_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_44_157_Closed_Text.style.display='none'; Codehighlighter1_44_157_Open_Image.style.display='inline'; Codehighlighter1_44_157_Open_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" width=11 align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;TestClass&nbsp;:&nbsp;MarshalByRefObject&nbsp;</SPAN><SPAN id=Codehighlighter1_44_157_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG height=20 src="http://www.cnblogs.com/Images/dot.gif" width=15></SPAN><SPAN id=Codehighlighter1_44_157_Open_Text><SPAN style="COLOR: #000000">{&nbsp; <BR><IMG id=Codehighlighter1_72_154_Open_Image onclick="this.style.display='none'; Codehighlighter1_72_154_Open_Text.style.display='none'; Codehighlighter1_72_154_Closed_Image.style.display='inline'; Codehighlighter1_72_154_Closed_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" width=11 align=top><IMG id=Codehighlighter1_72_154_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_72_154_Closed_Text.style.display='none'; Codehighlighter1_72_154_Open_Image.style.display='inline'; Codehighlighter1_72_154_Open_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;Call()&nbsp;</SPAN><SPAN id=Codehighlighter1_72_154_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG height=20 src="http://www.cnblogs.com/Images/dot.gif" width=15></SPAN><SPAN id=Codehighlighter1_72_154_Open_Text><SPAN style="COLOR: #000000">{&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">.Format(&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Hello&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.GetHashCode().ToString()&nbsp;);&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" width=11 align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp; <BR><IMG id=Codehighlighter1_177_545_Open_Image onclick="this.style.display='none'; Codehighlighter1_177_545_Open_Text.style.display='none'; Codehighlighter1_177_545_Closed_Image.style.display='inline'; Codehighlighter1_177_545_Closed_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" width=11 align=top><IMG id=Codehighlighter1_177_545_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_177_545_Closed_Text.style.display='none'; Codehighlighter1_177_545_Open_Image.style.display='inline'; Codehighlighter1_177_545_Open_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" width=11 align=top></SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;ClientTest&nbsp;</SPAN><SPAN id=Codehighlighter1_177_545_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG height=20 src="http://www.cnblogs.com/Images/dot.gif" width=15></SPAN><SPAN id=Codehighlighter1_177_545_Open_Text><SPAN style="COLOR: #000000">{&nbsp; <BR><IMG id=Codehighlighter1_202_542_Open_Image onclick="this.style.display='none'; Codehighlighter1_202_542_Open_Text.style.display='none'; Codehighlighter1_202_542_Closed_Image.style.display='inline'; Codehighlighter1_202_542_Closed_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" width=11 align=top><IMG id=Codehighlighter1_202_542_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_202_542_Closed_Text.style.display='none'; Codehighlighter1_202_542_Open_Image.style.display='inline'; Codehighlighter1_202_542_Open_Text.style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;Run()&nbsp;</SPAN><SPAN id=Codehighlighter1_202_542_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG height=20 src="http://www.cnblogs.com/Images/dot.gif" width=15></SPAN><SPAN id=Codehighlighter1_202_542_Open_Text><SPAN style="COLOR: #000000">{&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ChannelServices.RegisterChannel(&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;TcpClientChannel(&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Channel</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.GetHashCode().ToString(),&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;BinaryClientFormatterSinkProvider()&nbsp;)&nbsp;);&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top> <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TestClass&nbsp;tc&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(TestClass)&nbsp;Activator.GetObject(&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">typeof</SPAN><SPAN style="COLOR: #000000">(&nbsp;TestClass&nbsp;),&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">tcp://localhost:8086/Test</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;);&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(&nbsp;tc.Call()&nbsp;);&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" width=11 align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp; <BR><IMG height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" width=11 align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN> </DIV>
<P><BR><BR>　　先开启一个Server，然后执行两个Client。 </P>
<TABLE style="WIDTH: 600px; BORDER-COLLAPSE: collapse" cellSpacing=1 cellPadding=3 align=center bgColor=#660000 border=0>
<TBODY>
<TR bgColor=#ffcc66>
<TD align=middle width=21>No.</TD>
<TD align=middle width=42>对象</TD>
<TD align=middle width=32>线程</TD>
<TD align=middle width=63>LocalPort</TD>
<TD align=middle width=70>RemotePort</TD>
<TD width=190>操作</TD></TR>
<TR bgColor=#e0e0cc>
<TD align=middle>1</TD>
<TD align=middle>Server</TD>
<TD align=middle><STRONG>4008</STRONG> </TD>
<TD align=middle>8086</TD>
<TD align=middle>&nbsp;</TD>
<TD>绑定端口并开始监听</TD></TR>
<TR bgColor=#ffffcc>
<TD align=middle>2</TD>
<TD align=middle>Client1</TD>
<TD align=middle>2524</TD>
<TD align=middle>1174</TD>
<TD align=middle>8086</TD>
<TD>连接并发送请求</TD></TR>
<TR bgColor=#e0e0cc>
<TD align=middle>3</TD>
<TD align=middle>Server</TD>
<TD align=middle><STRONG>2840</STRONG> </TD>
<TD align=middle>8086</TD>
<TD align=middle>1174</TD>
<TD>返回信息</TD></TR>
<TR bgColor=#ffffcc>
<TD align=middle>4</TD>
<TD align=middle>Client1</TD>
<TD align=middle>2524</TD>
<TD align=middle>1174</TD>
<TD align=middle>8086</TD>
<TD>接受信息</TD></TR>
<TR bgColor=#ffff99>
<TD align=middle>5</TD>
<TD align=middle>Client2</TD>
<TD align=middle>2500</TD>
<TD align=middle>1175</TD>
<TD align=middle>8086</TD>
<TD>连接并发送请求</TD></TR>
<TR bgColor=#e0e0cc>
<TD align=middle>6</TD>
<TD align=middle>Server</TD>
<TD align=middle><STRONG>2292</STRONG> </TD>
<TD align=middle>8086</TD>
<TD align=middle>1175</TD>
<TD>返回信息</TD></TR>
<TR bgColor=#ffff99>
<TD align=middle>7</TD>
<TD align=middle>Client2</TD>
<TD align=middle>2524</TD>
<TD align=middle>1174</TD>
<TD align=middle>8086</TD>
<TD>接受信息</TD></TR></TBODY></TABLE>
<P>　　我们看到，这回Server一个监听线程(4008)，两个Client分别使用不同的线程和端口，这点和之前的情况差不多。但是这次Server针对Client1和Client2终于使用了两个不同的通信线程。那么Remoting怎么区分通信线程呢？我想是根据我们注册的信道。之前我们一个Client两个线程，都是通过同一个 TcpClientChannel。所以Server也相应的用同一个通信线程。而现在每个Client都使用独立的信道，Server端相应的也使用不同的网络连接。 <BR><BR>　　总结来说，Server端有一个主线程在我们创建ServerChannel时所指定的端口上负责监听。当客户端有请求时，Server为每一个ClientChannel分配一个辅助通信线程和一个专门的网络连接。在每一个信道上，可以同时处理多个请求。 <BR><BR>　　顺便提一下，通过网络跟踪还验证了这句话： <BR>　　MSDN:TcpChannel 打开并缓存与当时正在向另一个服务器发出请求的线程一样多的连接。客户端上的套接字连接将在处于不活动状态 15-20 秒钟之后关闭。 </P>
<TABLE style="WIDTH: 600px; BORDER-COLLAPSE: collapse" cellSpacing=1 cellPadding=3 align=center bgColor=#660000 border=0>
<TBODY>
<TR bgColor=#ffcc66>
<TD align=middle width=21>No.</TD>
<TD align=middle width=42>对象</TD>
<TD align=middle width=32>线程</TD>
<TD align=middle width=63>LocalPort</TD>
<TD align=middle width=70>RemotePort</TD>
<TD width=190>操作</TD></TR>
<TR bgColor=#ffffcc>
<TD align=middle>8</TD>
<TD align=middle>Client1</TD>
<TD align=middle>2524</TD>
<TD align=middle>1174</TD>
<TD align=middle>8086</TD>
<TD>关闭Socket，结束线程</TD></TR>
<TR bgColor=#e0e0cc>
<TD align=middle>9</TD>
<TD align=middle>Server</TD>
<TD align=middle><STRONG>2840</STRONG> </TD>
<TD align=middle>8086</TD>
<TD align=middle>1174</TD>
<TD>关闭Socket，结束线程</TD></TR>
<TR bgColor=#ffff99>
<TD align=middle>10</TD>
<TD align=middle>Client2</TD>
<TD align=middle>2500</TD>
<TD align=middle>1175</TD>
<TD align=middle>8086</TD>
<TD>关闭Socket，结束线程</TD></TR>
<TR bgColor=#e0e0cc>
<TD align=middle>11</TD>
<TD align=middle>Server</TD>
<TD align=middle><STRONG>2292</STRONG> </TD>
<TD align=middle>8086</TD>
<TD align=middle>1175</TD>
<TD>关闭Socket，结束线程</TD></TR></TBODY></TABLE>
<P><BR>　　在15秒未进行操作后，两个Channel在服务器和客户端的通信线程均被结束。 <BR><BR><BR><BR><BR><BR></P><img src ="http://www.cnblogs.com/kriss/aggbug/288900.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47986/" target="_blank">网易澄清:与暴雪合资公司仅提供技术支持</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>【转】 庞德致曹操：关于战胜关羽的可行性报告</title><link>http://www.cnblogs.com/kriss/archive/2005/12/01/288783.html</link><dc:creator>逸天</dc:creator><author>逸天</author><pubDate>Thu, 01 Dec 2005 13:07:00 GMT</pubDate><guid>http://www.cnblogs.com/kriss/archive/2005/12/01/288783.html</guid><wfw:comment>http://www.cnblogs.com/kriss/comments/288783.html</wfw:comment><comments>http://www.cnblogs.com/kriss/archive/2005/12/01/288783.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/kriss/comments/commentRss/288783.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/kriss/services/trackbacks/288783.html</trackback:ping><description><![CDATA[<P><FONT face=宋体 color=black size=3><SPAN>庞德致曹操：关于战胜关羽的可行性报告</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN></FONT><FONT color=black><SPAN>曹操批示：</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR>----------------&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　于禁同志，这是庞德同志的一份材料，内容充实，结合实际，分析深刻，转你一阅。望你本着放权而不放任、管理而不束缚、鼓励而不夸大、警告而不泼冷水的精神对其进行指挥。密切注意此人的具体表现，战斗开始后请你全权负责，视情酌办。</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US><BR>&nbsp;<BR>&nbsp;<BR><STRONG><B><FONT face=ˎ̥><SPAN>1</SPAN></FONT></B></STRONG></SPAN></FONT><STRONG><B><FONT face=宋体 color=black><SPAN>、开篇</SPAN></FONT></B></STRONG><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR>&nbsp;&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>敬爱的魏王千岁：</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US><BR>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　您好！</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR><BR></SPAN></FONT><FONT color=black><SPAN>　　我是庞德</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>--</SPAN></FONT><FONT color=black><SPAN>就是您一直记不住名字，老是称呼我</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>"</SPAN></FONT><FONT color=black><SPAN>那个谁</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&#8230;&#8230;</SPAN></FONT><FONT color=black><SPAN>那个绿脸的谁</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>"</SPAN></FONT><FONT color=black><SPAN>那个。首先，我对自己今天上午的表现向您道歉：在您询问谁敢协助于禁将军去战关羽的时候，我从最后面跳出来，使得您和大家都受到惊吓了，李典将军当众还怒斥我是</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>"</SPAN></FONT><FONT color=black><SPAN>癞蛤蟆蹦脚面</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>"--</SPAN></FONT><FONT color=black><SPAN>请允许我为自己卤莽的态度、丑陋的外表和困难的声带再次向您道歉！</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR><BR></SPAN></FONT><FONT color=black><SPAN>　　自从前年在汉中归顺于您以来，我一直深入学习您关于</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>"</SPAN></FONT><FONT color=black><SPAN>力为曹所出，马为曹所骑，刀为操所用</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>"</SPAN></FONT><FONT color=black><SPAN>的光辉思想，无时无刻不在想着为您的篡汉统一事业作出自己的贡献，现在，关羽侵犯襄、樊，形势危机，正是我报效大魏的好时机，因此过于兴奋，请魏王谅解。末将这次请命，不是出于一时的冲动，而是本着您</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>"</SPAN></FONT><FONT color=black><SPAN>理论联系实际</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>"</SPAN></FONT><FONT color=black><SPAN>的教导，进行了深入的研究，并认为这次我有相当的把握战胜关羽，挫他</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>"</SPAN></FONT><FONT color=black><SPAN>三十年不败</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>"</SPAN></FONT><FONT color=black><SPAN>的声价，进而为曹仁将军解围，为您的伟大事业作出新的、应有的贡献。以下是本人关于战胜关羽的可行性论证，请您审阅</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>--&nbsp;</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US><BR>&nbsp;<BR><STRONG><B><FONT face=ˎ̥><SPAN>&#183;</SPAN></FONT></B></STRONG></SPAN></FONT><STRONG><B><FONT face=宋体 color=black><SPAN>第一部分：关羽的搏斗资料及其分析</SPAN></FONT></B></STRONG><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp; </SPAN></FONT><FONT color=black><SPAN>具不完全统计，关羽自</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>25</SPAN></FONT><FONT color=black><SPAN>岁出世以来，进行的搏斗有记录的是</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>27</SPAN></FONT><FONT color=black><SPAN>场，其中一对一单挑共</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>23</SPAN></FONT><FONT color=black><SPAN>场（参见附录</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>1</SPAN></FONT><FONT color=black><SPAN>）。其单挑战绩为：</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>20</SPAN></FONT><FONT color=black><SPAN>胜，</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>3</SPAN></FONT><FONT color=black><SPAN>平，</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>0</SPAN></FONT><FONT color=black><SPAN>负</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>--</SPAN></FONT><FONT color=black><SPAN>这个战绩是令人恐惧的，其得到战神的绰号并威震华夏，的确是有这个实力的。通过对关羽具体格斗记录的分析，我发现其格斗特征如下：</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR><BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>1</SPAN></FONT><FONT color=black><SPAN>，斩杀率极高。在</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>20</SPAN></FONT><FONT color=black><SPAN>场胜利中，其斩杀对手为</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>16</SPAN></FONT><FONT color=black><SPAN>场，斩杀率为</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>80%</SPAN></FONT><FONT color=black><SPAN>！另有一人被生擒（王忠），一人被吓跑（吕常），二人次被战败（夏侯敦</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>2</SPAN></FONT><FONT color=black><SPAN>次）。</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US><BR>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>2</SPAN></FONT><FONT color=black><SPAN>，取胜速度极其迅速。其取胜记录中，一回合即斩杀或生擒对手为</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>10</SPAN></FONT><FONT color=black><SPAN>场，占</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>43</SPAN></FONT><FONT color=black><SPAN>。</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>5%</SPAN></FONT><FONT color=black><SPAN>，十回合以下的为</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>8</SPAN></FONT><FONT color=black><SPAN>场，约占</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>34</SPAN></FONT><FONT color=black><SPAN>。</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>7%</SPAN></FONT><FONT color=black><SPAN>。</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR><BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>3</SPAN></FONT><FONT color=black><SPAN>，持久战取胜艰难。十回合以上的为</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>3</SPAN></FONT><FONT color=black><SPAN>场（华雄、管亥、蔡阳），仅仅为</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>13</SPAN></FONT><FONT color=black><SPAN>。</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>1%</SPAN></FONT><FONT color=black><SPAN>。（另外两场为夏侯敦将军诈败。）</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR><BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>--</SPAN></FONT><FONT color=black><SPAN>通过以上分析，可见关羽的格斗诀窍可概括为：速度快、力量大、下手狠、刀法准。这是一种人、马、刀三位一体，速战速决的战斗方法，关羽身高</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>9</SPAN></FONT><FONT color=black><SPAN>尺，合西尺</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>2</SPAN></FONT><FONT color=black><SPAN>。</SPAN></FONT><?xml:namespace prefix = st1 /><st1:chmetcnv TCSC="0" NumberType="1" Negative="False" HasSpace="False" SourceValue="14" UnitName="米" w:st="on"><FONT face=ˎ̥ color=black><SPAN lang=EN-US>14</SPAN></FONT><FONT color=black><SPAN>米</SPAN></FONT></st1:chmetcnv><FONT color=black><SPAN>，体重</SPAN></FONT><st1:chmetcnv TCSC="0" NumberType="1" Negative="False" HasSpace="False" SourceValue="115" UnitName="公斤" w:st="on"><FONT face=ˎ̥ color=black><SPAN lang=EN-US>115</SPAN></FONT><FONT color=black><SPAN>公斤</SPAN></FONT></st1:chmetcnv><FONT color=black><SPAN>，爆发力极其惊人，其赤兔马的绝对冲击速度可达</SPAN></FONT><st1:chmetcnv TCSC="0" NumberType="1" Negative="False" HasSpace="False" SourceValue="530" UnitName="码" w:st="on"><FONT face=ˎ̥ color=black><SPAN lang=EN-US>530</SPAN></FONT><FONT color=black><SPAN>码</SPAN></FONT></st1:chmetcnv><FONT color=black><SPAN>。因此，许多战斗力甚至本来和他差不多的战将如颜良、文丑等人都吃了他</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>"</SPAN></FONT><FONT color=black><SPAN>快、准、狠</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>"</SPAN></FONT><FONT color=black><SPAN>的亏，这也是需要我们引起极端重视的。</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US><BR><BR><STRONG><B><FONT face=ˎ̥><SPAN>&#183;</SPAN></FONT></B></STRONG></SPAN></FONT><STRONG><B><FONT face=宋体 color=black><SPAN>第二部分：我们战胜关羽的机会在哪里？</SPAN></FONT></B></STRONG><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp; </SPAN></FONT><FONT color=black><SPAN>我认真分析了关羽</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>23</SPAN></FONT><FONT color=black><SPAN>场决斗中平局的战例：与管亥</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>30</SPAN></FONT><FONT color=black><SPAN>合战平，与黄钟</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>2</SPAN></FONT><FONT color=black><SPAN>次战平的记录，发现，关羽的格斗技巧并非无懈可击：</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US><BR>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>1</SPAN></FONT><FONT color=black><SPAN>，只要坚持</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>10</SPAN></FONT><FONT color=black><SPAN>个回合，关羽取胜就极其困难</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>--</SPAN></FONT><FONT color=black><SPAN>其持久作战后杀伤力将大大折扣。这里最关键的是鼎住其头三个回合的冲击。</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR><BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>2</SPAN></FONT><FONT color=black><SPAN>，暗器的使用。关羽平生不喜欢用暗器，对暗器的预防也是他的弱项，尤其是左臂：比如过五关时曾经被韩福射中左臂</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>--</SPAN></FONT><FONT color=black><SPAN>这里是他的软肋！如果使用暗器，战胜关羽的机会会增加很多。比如黄钟，如果不是手下留情，关羽早没命了。在这方面，他比张飞、马超、黄忠要弱。</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR><BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>3</SPAN></FONT><FONT color=black><SPAN>，年龄的问题。关羽现在已经是</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>58</SPAN></FONT><FONT color=black><SPAN>岁的人了，根据曹仁将军从前线传来的资料，关羽目前的体重似乎已经接近</SPAN></FONT><st1:chmetcnv TCSC="0" NumberType="1" Negative="False" HasSpace="False" SourceValue="260" UnitName="公斤" w:st="on"><FONT face=ˎ̥ color=black><SPAN lang=EN-US>260</SPAN></FONT><FONT color=black><SPAN>公斤</SPAN></FONT></st1:chmetcnv><FONT color=black><SPAN>，其速度，力量一定不如当年了。更要命的是他的性格：因为爱面子，他不肯换一把稍微轻便一点的武器，仍然使用他</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>82</SPAN></FONT><FONT color=black><SPAN>斤的宝刀，以至于力不从心；因为重感情，他没有换一匹年轻一点的马，而是仍然乘坐魏王赐的赤兔兽，现在它的绝对冲击速度估计不超过</SPAN></FONT><st1:chmetcnv TCSC="0" NumberType="1" Negative="False" HasSpace="False" SourceValue="420" UnitName="码" w:st="on"><FONT face=ˎ̥ color=black><SPAN lang=EN-US>420</SPAN></FONT><FONT color=black><SPAN>码</SPAN></FONT></st1:chmetcnv><FONT color=black><SPAN>。</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US><BR><BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>--</SPAN></FONT><FONT color=black><SPAN>总上，关羽现在的战斗力应当不足</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>40</SPAN></FONT><FONT color=black><SPAN>岁时的</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>65%</SPAN></FONT><FONT color=black><SPAN>了，而我的战斗力，经过徐晃等将军的测验，和当年的颜良相当，只是略逊于文丑和华雄，因此只要策略得当，战胜关羽是完全可能的！</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US><BR><BR><STRONG><B><FONT face=ˎ̥><SPAN>&#183;</SPAN></FONT></B></STRONG></SPAN></FONT><STRONG><B><FONT face=宋体 color=black><SPAN>第三部分：我的具体计划</SPAN></FONT></B></STRONG><STRONG><B><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;</SPAN></FONT></B></STRONG><B><FONT face=ˎ̥ color=black><SPAN lang=EN-US><BR></SPAN></FONT></B><FONT face=ˎ̥ color=black><SPAN lang=EN-US><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1</SPAN></FONT><FONT color=black><SPAN>，和关羽开始交战，我坚决不能看他的脸（很多人就是因此被惊吓送命的），而是紧紧盯着他的刀！</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR><BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>2</SPAN></FONT><FONT color=black><SPAN>，充分利用自己年龄的优势，争取多与他发生兵器的直接碰撞，这样就可以最大限度地防止关羽刀法的变化，把他拖住。只要十回合之内没有被斩，那么关羽取胜的机会将大大降低！</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR><BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>3</SPAN></FONT><FONT color=black><SPAN>，利用持久战把关羽激怒，然后利用他急于获胜的心理引诱他追赶</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>--</SPAN></FONT><FONT color=black><SPAN>以暗箭伤之。他现在身体发福，闪躲动作退化，这一箭即使不能取他性命，也必然伤之，我再从而赶上，即使不能取其首级，也必将大败之！</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　尊敬的魏王，如果我的申请得到了您的允许，我将以您</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>"</SPAN></FONT><FONT color=black><SPAN>三为</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>"</SPAN></FONT><FONT color=black><SPAN>的光辉思想为指导，争取最后的胜利。如果我的申请没有被您接受，我将更加努力刻苦地学习，尽早达到一个合格大将的思想和作战水平。现在，您身边的大将基本上都是和关羽一样，出生于上世纪</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>60</SPAN></FONT><FONT color=black><SPAN>年代，该是我们</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>80</SPAN></FONT><FONT color=black><SPAN>年代出生的年轻人出头的时候了，我们一定鼓起勇气、坚定信心，把更重的担子挑起来</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>--</SPAN></FONT><FONT color=black><SPAN>请魏王看我的行动吧！<BR></SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US><BR></SPAN></FONT><FONT color=black><SPAN>此致</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;</SPAN></FONT><FONT color=black><SPAN>敬礼</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN></FONT><FONT color=black><SPAN>庞德（令明）上</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US><BR><STRONG><B><FONT face=ˎ̥><SPAN>2</SPAN></FONT></B></STRONG></SPAN></FONT><STRONG><B><FONT face=宋体 color=black><SPAN>、附录</SPAN></FONT></B></STRONG><STRONG><B><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;</SPAN></FONT></B></STRONG><B><FONT face=ˎ̥ color=black><SPAN lang=EN-US><BR></SPAN></FONT></B><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>附录</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>1</SPAN></FONT><FONT color=black><SPAN>：关羽三十年搏斗资料统计（根据罗贯中同志材料整理）</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>1</SPAN></FONT><FONT color=black><SPAN>，程远志：一刀批（第一回）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;2</SPAN></FONT><FONT color=black><SPAN>，华雄：</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;</SPAN></FONT><FONT color=black><SPAN>斗杀（第四回）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>3</SPAN></FONT><FONT color=black><SPAN>，吕布：三胜一（第五会）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;4</SPAN></FONT><FONT color=black><SPAN>，管亥：斗杀（数十合）（第</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>11</SPAN></FONT><FONT color=black><SPAN>回）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>5</SPAN></FONT><FONT color=black><SPAN>，纪灵：三十合平，（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>14</SPAN></FONT><FONT color=black><SPAN>回）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;6</SPAN></FONT><FONT color=black><SPAN>，荀正：一刀劈（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>14</SPAN></FONT><FONT color=black><SPAN>回）</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>7</SPAN></FONT><FONT color=black><SPAN>，吕布：与张飞二打一，吕布无心恋战。（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>19</SPAN></FONT><FONT color=black><SPAN>回）；<BR></SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US><SPAN>　　</SPAN>8</SPAN></FONT><FONT color=black><SPAN>，吕布：与张飞二打一，吕布突围失败。（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>20</SPAN></FONT><FONT color=black><SPAN>回）</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>9</SPAN></FONT><FONT color=black><SPAN>，车胄：数合斩之（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>21</SPAN></FONT><FONT color=black><SPAN>回）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;10</SPAN></FONT><FONT color=black><SPAN>，王忠：生擒，（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>22</SPAN></FONT><FONT color=black><SPAN>回）</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>11</SPAN></FONT><FONT color=black><SPAN>，夏侯惇：十馀合，惇诈败（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>25</SPAN></FONT><FONT color=black><SPAN>回）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;12</SPAN></FONT><FONT color=black><SPAN>，徐晃、许褚：杀退二人（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>25</SPAN></FONT><FONT color=black><SPAN>回）</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>13</SPAN></FONT><FONT color=black><SPAN>，颜良：一刀劈。（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>25</SPAN></FONT><FONT color=black><SPAN>回）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;14</SPAN></FONT><FONT color=black><SPAN>，文丑：三合，追杀。（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>26</SPAN></FONT><FONT color=black><SPAN>回）</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>15</SPAN></FONT><FONT color=black><SPAN>，孔秀：一合杀之（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>27</SPAN></FONT><FONT color=black><SPAN>回）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;16</SPAN></FONT><FONT color=black><SPAN>，孟坦：三合，追杀。（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>27</SPAN></FONT><FONT color=black><SPAN>回）</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>17</SPAN></FONT><FONT color=black><SPAN>，韩福：追杀（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>27</SPAN></FONT><FONT color=black><SPAN>回）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;18</SPAN></FONT><FONT color=black><SPAN>，卞喜：一刀劈（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>27</SPAN></FONT><FONT color=black><SPAN>回）</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>19</SPAN></FONT><FONT color=black><SPAN>，王植：一刀劈（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>27</SPAN></FONT><FONT color=black><SPAN>回）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;20</SPAN></FONT><FONT color=black><SPAN>，秦琪：一合杀之（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>27</SPAN></FONT><FONT color=black><SPAN>回）</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>21</SPAN></FONT><FONT color=black><SPAN>，夏侯惇：十合，住手（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>28</SPAN></FONT><FONT color=black><SPAN>回）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;22</SPAN></FONT><FONT color=black><SPAN>，蔡阳：斗杀（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>28</SPAN></FONT><FONT color=black><SPAN>回）</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>23</SPAN></FONT><FONT color=black><SPAN>，夏侯惇：数合，诈败（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>39</SPAN></FONT><FONT color=black><SPAN>回）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;24</SPAN></FONT><FONT color=black><SPAN>，黄忠：</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>100</SPAN></FONT><FONT color=black><SPAN>合，平。（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>53</SPAN></FONT><FONT color=black><SPAN>回）</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>25</SPAN></FONT><FONT color=black><SPAN>，黄忠：五六十合，平。（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>53</SPAN></FONT><FONT color=black><SPAN>回）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;26</SPAN></FONT><FONT color=black><SPAN>，夏侯存：一合杀之（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>73</SPAN></FONT><FONT color=black><SPAN>回）<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>27</SPAN></FONT><FONT color=black><SPAN>，吕常王忠：未战吓走（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>73</SPAN></FONT><FONT color=black><SPAN>回）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;28</SPAN></FONT><FONT color=black><SPAN>，庞德：百余合，平（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>74</SPAN></FONT><FONT color=black><SPAN>回）</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>--------------------------&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　以下为后文：</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>29</SPAN></FONT><FONT color=black><SPAN>，庞德：</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>50</SPAN></FONT><FONT color=black><SPAN>合，中箭败（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>74</SPAN></FONT><FONT color=black><SPAN>回）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;30</SPAN></FONT><FONT color=black><SPAN>，徐晃：八十余合，平（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>76</SPAN></FONT><FONT color=black><SPAN>回）</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;<BR></SPAN></FONT><FONT color=black><SPAN>　　</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>31</SPAN></FONT><FONT color=black><SPAN>，蒋钦、韩当、周泰、丁奉、徐盛：被围（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>76</SPAN></FONT><FONT color=black><SPAN>）；</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>&nbsp;32</SPAN></FONT><FONT color=black><SPAN>，璋：三合败（</SPAN></FONT><FONT face=ˎ̥ color=black><SPAN lang=EN-US>7677</SPAN></FONT><FONT color=black><SPAN>回）</SPAN></FONT></P><img src ="http://www.cnblogs.com/kriss/aggbug/288783.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47985/" target="_blank">杰克逊悼念仪式或成史上最大规模Web活动</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>Remoting多个信道(Chennel)的注册问题</title><link>http://www.cnblogs.com/kriss/archive/2005/11/30/288177.html</link><dc:creator>逸天</dc:creator><author>逸天</author><pubDate>Wed, 30 Nov 2005 15:19:00 GMT</pubDate><guid>http://www.cnblogs.com/kriss/archive/2005/11/30/288177.html</guid><wfw:comment>http://www.cnblogs.com/kriss/comments/288177.html</wfw:comment><comments>http://www.cnblogs.com/kriss/archive/2005/11/30/288177.html#Feedback</comments><slash:comments>14</slash:comments><wfw:commentRss>http://www.cnblogs.com/kriss/comments/commentRss/288177.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/kriss/services/trackbacks/288177.html</trackback:ping><description><![CDATA[　　一般情况下我们用Remoting一个信道应该就够用了，因为程序要么是客户端，要么是服务器端。但是有时候也会出现一个客户端需要连接多个服务器端的情况，或者一个程序既作为服务器端(针对内网)，又作为客户端(针对外网)。这个时候就需要注册多个信道了。<BR>　　根据一般的经验，客户端信道和服务器端信道应该是不冲突的。但实际的情况呢？看一下以下的代码： 
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000">IChannel&nbsp;serverChannel&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;TcpServerChannel(&nbsp;</SPAN><SPAN style="COLOR: #000000">5000</SPAN><SPAN style="COLOR: #000000">&nbsp;); <BR>ChannelServices.RegisterChannel(&nbsp;serverChannel,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">&nbsp;); <BR><BR>IChannel&nbsp;clientChannel&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;TcpClientChannel(); <BR>ChannelServices.RegisterChannel(&nbsp;clientChannel&nbsp;);</SPAN> </DIV></SPAN><BR>　　运行后会出现异常&#8220;信道 'tcp' 已注册。&#8221;(RemotingException) <BR><BR>　　注册两个客户端信道也一样会出现这个错误： <BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000">IChannel&nbsp;channel1&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;TcpClientChannel(); <BR>ChannelServices.RegisterChannel(&nbsp;channel1,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">&nbsp;); <BR>IChannel&nbsp;channel2&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;TcpClientChannel(); <BR>ChannelServices.RegisterChannel(&nbsp;channel2,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">&nbsp;);</SPAN> </DIV><BR>　　开始我怀疑是端口冲突，给每个信道分别设置不同的端口： <BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000">Hashtable&nbsp;props1&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Hashtable(); <BR>props1[</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">port</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">5001</SPAN><SPAN style="COLOR: #000000">; <BR>IChannel&nbsp;channel1&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;TcpClientChannel(&nbsp;props1,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;BinaryClientFormatterSinkProvider()&nbsp;); <BR>ChannelServices.RegisterChannel(&nbsp;channel1,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">&nbsp;); <BR>Hashtable&nbsp;props2&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Hashtable(); <BR>props2[</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">port</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">5002</SPAN><SPAN style="COLOR: #000000">; <BR>IChannel&nbsp;channel2&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;TcpClientChannel(&nbsp;props2,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;BinaryClientFormatterSinkProvider()&nbsp;); <BR>ChannelServices.RegisterChannel(&nbsp;channel2,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">&nbsp;);</SPAN> </DIV><BR>　　错误依旧。想想也是，如果端口冲突，应该是这种错误：&#8220;通常每个套接字地址(协议/网络地址/端口)只允许使用一次。&#8221;(SocketException) <BR>　　再分析一下原来的错误：&#8220;信道 'tcp' 已注册。&#8221;。难道是信道的名字冲突？ <BR>　　赶紧把channel的ChannelName打印出来看一下: <BR>　　Console.WriteLine( "The Default Channel Name is " +&nbsp;(new TcpClientChannel()).ChannelName ); <BR>　　"The Default Channel Name is tcp"... <BR><BR>　　问题找到。接下来要做的就是在注册不同信道的时候，显式指定其信道名称。ServerChannel和ClientChannel各有不同的方法，以下示例其一： <BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000">IChannel&nbsp;channel1&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;TcpClientChannel(&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Channel1</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;BinaryClientFormatterSinkProvider()&nbsp;); <BR>ChannelServices.RegisterChannel(&nbsp;channel1,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">&nbsp;); <BR>IChannel&nbsp;channel2&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;TcpClientChannel(&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Channel2</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;BinaryClientFormatterSinkProvider()&nbsp;); <BR>ChannelServices.RegisterChannel(&nbsp;channel2,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">&nbsp;);</SPAN> </DIV><BR>　　BTW:因为很少看到网上Remoting的文章提到多信道的注册，所以把这个贴出来。也许大家注册信道的时候就指定了名字，这样就不会有这个问题。<IMG height=19 src="http://www.cnblogs.com/Emoticons/emteeth.gif" width=19 align=absMiddle border=0>&nbsp;另外，以上均是在.NET 2.0平台上。 <BR><BR>　　MSDN上的相关说明:<BR>　　ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconchannels.htm<BR>　　"信道名称在应用程序域中必须是唯一的。例如，由于默认信道具有名称，因此，若要在一个应用程序域中注册两个 <B>HttpChannel</B> 对象，就必须在注册它们之前更改信道的名称。"<img src ="http://www.cnblogs.com/kriss/aggbug/288177.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47984/" target="_blank">《商业周刊》:Mozilla的志愿者开发模式被复制</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>基于强名称签名的代码访问保护及其改进</title><link>http://www.cnblogs.com/kriss/archive/2005/10/24/261131.html</link><dc:creator>逸天</dc:creator><author>逸天</author><pubDate>Mon, 24 Oct 2005 13:52:00 GMT</pubDate><guid>http://www.cnblogs.com/kriss/archive/2005/10/24/261131.html</guid><wfw:comment>http://www.cnblogs.com/kriss/comments/261131.html</wfw:comment><comments>http://www.cnblogs.com/kriss/archive/2005/10/24/261131.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.cnblogs.com/kriss/comments/commentRss/261131.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/kriss/services/trackbacks/261131.html</trackback:ping><description><![CDATA[摘要: 先说点题外话。首先要寒一下自己，有半年多没有更新blog，实在是偷懒至极。。其间心得倒也不少，如果只是贴代码，倒是挺容易，不过这样的post在我看来，是最垃圾的，肯定骂声无数；但要把问题讲清楚透彻，又比写代码要费劲得多　　言归正传。在我看来，利用.NET开发应用程序，有两个比较突出的问题，就是性能和安全性。当然在Web应用上这两点倒不是很大的问题。　　安全方面，除了强名称和混淆编译等部署端的保护外&nbsp;&nbsp;<a href='http://www.cnblogs.com/kriss/archive/2005/10/24/261131.html'>阅读全文</a><img src ="http://www.cnblogs.com/kriss/aggbug/261131.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47977/" target="_blank">Mono 的Virtual PC 虚拟机</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item></channel></rss>