现在的位置: 首页 > 综合 > 正文

Remoting客户端和服务器段对象不一致的测试

2012年11月06日 ⁄ 综合 ⁄ 共 1977字 ⁄ 字号 评论关闭

Remoting虽然都出了好多年了,但我们项目有一部分还在用remoting,前段时间一个同事说,我的一个remoting服务端版本升级后,方法中其中一个参数是一个类对象,但这个对象新增了一些字段,但由于客户端没升级好,还用老的对象去调用,是否会有问题。经过简单测试,我发现完全没问题,可以互相调用。

测试了三种情况:

1、 客户端的类对象比服务端少一些字段。

2、 客户端的类对象比服务端多一些字段。

3、 客户端的类对象和服务端对象不一样,命名都一样。

最后证明第一、二种情况都是没问题的,第三种情况如果对象命名空间和程序集名称一样,也是没有问题的(类库没有进行任何签名)。

测试工程如下:

 

Common是公共类库和接口预定。

CommonII是和Common包含一样的文件,命名控件和生成的类库都一样。

PayServerRemoting服务端,引用CommonPayServiceHandler

PayServiceHandler是处理Remoting服务端的真实请求对象,引用Common

RemotingClientRemoting客户端,引用Common(后续测试引用CommonII)。

 

PayServer代码:

 

        static void Main(string[] args)

        {

            int port = 7721;

            string objectUri = "PayServer";

 

            TcpServerChannel tcpChannel = new TcpServerChannel(port);

            RemotingConfiguration.RegisterWellKnownServiceType(typeof(PayService), objectUri, WellKnownObjectMode.SingleCall);

 

            Console.WriteLine("服务已启动...");

            Console.ReadKey();

        }

RemotingClient代码:

 

        static void Main(string[] args)

        {

            int port = 7721;

            string objectUri = "PayServer";

            string uri = "TCP://127.0.0.1:" + port + "/" + objectUri;

            IPayService service = (IPayService)Activator.GetObject(typeof(IPayService), uri);

            PayInfo info = new PayInfo();

            //info.Account = 230.5m;

            info.payID = 1;

            info.ProviderID = 20;

            info.OtherInt = 10;

            info.OtherStr = "abc";

            info.Consumer = new ConsumerInfo(){ ConsumerID = 10,

                //ConsumerName = "lawson",

                ConsumerPhone = "123456"};

            string value = service.GetPayAccount(info);

 

            Console.WriteLine(value);

            Console.ReadKey();

        }

当客户端少Account字段时,服务端正常收到请求,Account的值为0,当客户端的ConsumerInfo对象里少ConsumerName时,服务端正常收到请求,ConsumerName的值为null

当客户端多OtherInt,OtherStr时,服务端正常收到请求,没这两个字段的值。

当客户端换引用CommonII时,CommonII内部类的命名空间和Common一样,并且CommonII的类库生成也为Common.dll,服务端正常接受请求,正常处理。

当我为原始Common程序集添加一个签名,用MySNK.pfx签名后,客户端引用不管Common还是CommonII都会提示:由于安全限制,无法访问类型 。。。的错误,通过网络搜索,没有找到合适解决方案。

 

/Files/Lawson/RemotingObjectTests2011.12.10.rar

抱歉!评论已关闭.