开始以为我的Remoting配置基本可以了,可最近又出现了一些问题,自己进行简单的摸索和实践,记录如下。
8 、发现自己的数据库连接类ConnectionInfo在web service中作为参数出现无法序列化的错误,由于有public的属性是 CultureInfo 的,无法实现序列化(由于 CultureInfo 没有实现 ISerializable 接口),只好把类型改为string;既然remoting调用远程对象时不便于调试,所以可以先把需要序列化的类用Web Service调试通过再使用,也是一种调试remoting的方法;
9、前面说到出现错误“由于安全限制,无法访问对象”的错误,和强名有关,其实那不是真正的解决办法;可以通过在配置文件中设置 typeFilterLevel="Full" 来解决,客户端和服务器端的配置文件都需要设置。参见: http://www.thinktecture.com/Resources/RemotingFAQ/Changes2003.html
You can do this either by using a configuration file like this (for server side):
1<configuration>
2<system.runtime.remoting>
3<application>
4<channels>
5<channel port="1234" ref="http">
6<serverproviders>
7<provider ref="wsdl"></provider>
8 ** <formatter ref="soap" typefilterlevel="Full"></formatter>
9<formatter ref="binary" typefilterlevel="Full"></formatter>
10 ** </serverproviders>
11<clientproviders>
12<formatter ref="binary"></formatter>
13</clientproviders>
14</channel>
15</channels>
16<service>
17<!-- ... Add your services here ... -->
18</service>
19</application>
20</system.runtime.remoting>
21</configuration>
In this case, a matching client-side configuration file which allows the reception of events and callbacks, would look like this:
1<configuration>
2<system.runtime.remoting>
3<application>
4<channels>
5<channel port="0" ref="http">
6<clientproviders>
7<formatter ref="binary"></formatter>
8</clientproviders>
9<serverproviders>
10 ** <formatter ref="binary" typefilterlevel="Full"></formatter>
11 ** </serverproviders>
12</channel>
13</channels>
14<client>
15<!-- ... Add your classes here ... -->
16</client>
17</application>
18</system.runtime.remoting>
19</configuration>
10、按照如上的格式进行配置文件的修改后,终于不出现“由于安全限制,无法访问对象”的错误了,可是出现
“mscorlib.dll 中出现无法处理的异常类型 System.Runtime.Serialization. SerializationException。
其他信息:BinaryFormatter 版本不兼容。收到的版本为 1008738336.1684104552”的错误,
这种错误大部分“不是”因为版本不兼容 ,而是因为客户端无法分析文本格式的错误响应。为了真正的错误信息,我把
格式程序从 binary 改为 soap 。
11、把需要序列化的类ConnectionInfo和其他remoting远程类一样,添加到配置文件中(服务器端Web.Config中的
1<service>
2 节和客户端配置文件中),哈哈,终于通过了。(不过我还是没明白序列化的类为何也要进行配置?)
3 12、发现静态(static)的方法即使进行Remoting配置,调用的竟然是本的方法,看来如果需要调用远程的static方法,
4 只有再封装成实例方法供客户端调用了。</service>