利用.NET Remoting 写了一个简简单单的服务端HelloServer01和客户端ClientHello
第一次:
服务端:ChannelServiec.RegisterChannel(new TcpServerChannel(8888),false);
       RemotingConfiguration.RegisterWellKnowServiceType(typeof(Hello),"hello",WellKnownObjectMode.SingleCall);
客户端
ChannelServiec.RegisterChannel(new TcpClientChannel(),false);
       RemotingConfiguration.RegisterWellKnowServiceType(typeof(Hello),"tcp://127.0.0.1/8888/hello");结果:由客户端调用远程对象,客户端有输出,服务也有输出.
第二资:
   改用远程配置文件配置信道信息和远程对象信息
RemotingConfiguration.Configure("sever.config")

RemotingConfiguration.Configure("client.config")
同样的操作,同样的调用,结果却不相同
结果:
服务端没有输出显示,客户端有输出,而且原来在服务端输出的东西全部跑到客户端这边来了苦思不得其解,只有求助各位大侠了.

解决方案 »

  1.   

    这是client.config文件<?xml version="1.0" encoding="utf-8" ?>
    <Configuration>
      <System.Runatime.Remoting>
        <application>
          <client>
            <wellknown type="HelloServer01.HelloObject,HelloObject" url="tcp://127.0.0.1:8888/hello"></wellknown>
          </client>
          <channels>
                <channel ref="tcp" displayName="TcpChannel(Hellserver)"/>
          </channels>
        </application>
      </System.Runatime.Remoting>
    </Configuration>这是server.config文件<?xml version="1.0" encoding="utf-8" ?>
    <Configuration>
      <System.Runtime.Remoting>
        <application>
          <service>
            <wellknown type="HelloServer01.HelloObject,HelloObject" mode="SinglCall" ObjectUrl="hello"/>
          </service>
          <channels>
            <channel ref="tcp" displayName="TcpChannel(HelloServer)" port="8888"/>
          </channels>
        </application>
      </System.Runtime.Remoting>
    </Configuration>
      

  2.   

    //这是服务端
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.Remoting;
    using System.Runtime.Remoting.Channels;
    using System.Runtime.Remoting.Channels.Tcp;
    namespace HelloServer01
    {
        public class HelloObject : System.MarshalByRefObject
        {
            public HelloObject()
            {
                Console.WriteLine("HellObject is Contructor!");
            }
            ~HelloObject()
            {
                Console.WriteLine("HellObject is DeContructor!");
            }
            public Hello.MySerialObject GetMySerlial
            {
                get
                {
                    return new Hello.MySerialObject();
                }
            }
            public Hello.MyRemoteObject GetMyRemote
            {
                get
                {
                    return new Hello.MyRemoteObject();
                }
            }
        }    class Program
        {
            static void Main(string[] args)
            {
                RemotingConfiguration.Configure("server.config");
                Console.WriteLine("请按任意键退出。");
                Console.ReadKey();
            }
        }
    }
      

  3.   

    这是客户端:using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.Remoting;
    using System.Runtime.Remoting.Channels;
    using System.Runtime.Remoting.Channels.Tcp;
    using Hello;
    using HelloServer01;
    namespace ClientHello
    {
        class Program
        {
            static void Main(string[] args)
            {
              
                RemotingConfiguration.Configure("server.config");
                HelloServer01.HelloObject obj = new HelloObject();
                if (obj != null)
                {
                    Hello.MySerialObject ser = obj.GetMySerlial;
                    if (!RemotingServices.IsTransparentProxy(ser))
                    {
                        Console.WriteLine("ser is not Proxy");
                    }
                    string method1=ser.Foo();
                    Console.WriteLine(method1);
                    Hello.MyRemoteObject re = obj.GetMyRemote;
                    if (RemotingServices.IsTransparentProxy(re))
                    {
                        Console.WriteLine("re is Proxy");
                    }
                    re.Foo();
                   
                }
                Console.WriteLine("请按任意键退出.");
                Console.ReadKey();
            }
        }
    }
      

  4.   

    这是Hello程序集:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.Serialization.Formatters.Binary;namespace Hello
    {
        [Serializable]
        public class MySerialObject
        {
            private string a;
            public MySerialObject()
            {
                Console.WriteLine("MySerialObject is Constructor!");
            }
            public string A
            {
                get
                {
                    Console.WriteLine("A is Called!");
                    return a;
                }
                set
                {
                    a = value;
                }
            }
            public string Foo()
            {
                Console.WriteLine("MySerlialObject.Foo Called!");
                return "Serial";
            }
        }
        public class MyRemoteObject : System.MarshalByRefObject
        {
            private string a;
            public MyRemoteObject()
            {
                Console.WriteLine("MyRemoteObject is Constructor!");
            }
            public string A
            {
                get
                {
                    Console.WriteLine("MyRemoteObject.A is Called!");
                    return a;
                }
                set
                {
                    a = value;
                }
            }
            public void Foo()
            {
                Console.WriteLine("MyRemotObject.Foo is Called!");
                
            }
        }
       }
      

  5.   

    顺便提一下
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.runtime.remoting>
        <application>
          <service>
            <wellknown type="Hello,HelloObject" mode="SingleCall" objectUri="hello"/>
          </service>
          <channels>
            <channel ref="tcp" port="8888" displayName="TcpChannel(HelloServer)"></Channel>
          </channels>
        </application>
      </system.runtime.remoting>
    </configuration>
    这个配置文件是不是有问题,当我用RemotingConfiguration.Configure("server.config",false)时老是提示channel附近有错误,但我找来找去都找不出来错误在哪里.
      

  6.   

    在项目中添加配件文件App.config,配置好后,生成方案后会自动在Debug目录下生成client.exe.config或者server.exe.config,(生成什么名称主要是看你的程序名称是什么),之后再用RemotingConfiguration("client.exe.config",false),结果还是不行啊,各位老大啊,有没有办法啊
      

  7.   

    楼主,你的config文件问题多得很啊。
    下面是我修改过的,好多个拼写错误:
    server.exe.config:<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <system.runtime.remoting>
    <application>
    <service>
    <wellknown type="HelloServer01.HelloObject, HelloServer01" mode="SingleCall" objectUri="hello"/>
    </service>
    <channels>
    <channel ref="tcp" displayName="TcpChannel(HelloServer)" port="8888"/>
    </channels>
    </application>
    </system.runtime.remoting>
    </configuration>client.exe.config:<?xml version="1.0" encoding="utf-8"   ?>
    <configuration>
    <system.runtime.remoting>
    <application>
    <client>
    <wellknown type="HelloServer01.HelloObject, HelloServer01" url="tcp://localhost:8888/hello"></wellknown>
    </client>
    <channels>
    <channel ref="tcp" displayName="TcpChannel(Hellserver)" />
    </channels>
    </application>
    </system.runtime.remoting>
    </configuration>要注意以下几个问题:
    1、<wellknown>的type属性一定要按照"type,assembly"的格式来写。其中type要full type name,把前面的所有命名空间都加上。assembly要真正的assembly name,可以在项目上单击右键,选择属性,看看里面的assembly name是什么。如果assembly有强签名,需要加上版本号和public key。
    2、server.exe.config中的objectUri属性名称不要写成ObjectUrl。
    3、<configuration>不要错写成<Configuration>
    4、<system.runtime.remoting>不要错写成<System.Runatime.Remoting>或者<System.Runtime.Remoting>在我这里运行通过了,结果为:
    client.exe:ser is not Proxy
    MySerlialObject.Foo   Called!
    Serial
    re is Proxy
    Press any key to exit...server.exe:Press any key to exit...
    HellObject is Contructor!
    MySerialObject   is   Constructor!
    HellObject is Contructor!
    MyRemoteObject   is   Constructor!
    MyRemotObject.Foo   is   Called!
    HellObject is DeContructor!
    HellObject is DeContructor!如果你那里还不通过,可以先把服务器跑起来,然后在另一个command prompt中输入"telnet localhost 8888",如果服务器没有问题,telnet应该可以正确地连接到8888端口,你输入几个回车之后有一个exception会被抛出来。这样可以把服务器的channel问题先排除掉。然后就是客户端了,你自己再试试好了。
      

  8.   

    TO : Jimonline 
    还是不行啊
    不知道哪里在做错了,真的晕死~~
    client.exe.config用telnet通过测试,服务器跑起来了但结果还是一样啊
    生成的时候,老是出现一大堆说:没有找到"XXXX"架构信息。
      

  9.   

    //这里客户端的配置文件:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.runtime.remoting>
        <application>
          <client>
            <wellknown type="RemotingObject.Hello,RemotingObject" url="tcp://127.0.0.1:8888/hello" />
          </client>
          <channels>
            <channel ref="tcp" displayName="TcpChannel(HelloClient)"/>
          </channels>
        </application>
      </system.runtime.remoting>
    </configuration>//这是服务端的配置文件:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.runtime.remoting>
        <application>
          <service>
            <wellknown type="RemotingObject.Hello,RemotingObject" mode="SingleCall" objectUri="hello" />
          </service>
          <channels>
            <channel ref="tcp" port="8888" displayName="TcpChannel(HelloServer)"/>
          </channels>
        </application>
      </system.runtime.remoting>
    </configuration>运行的时候老是提示
    消息 1 未能找到元素“application”的架构信息。 D:\项目\RemotingHello\HelloClient\App.config 4 6 HelloClient
    消息 2 未能找到元素“client”的架构信息。 D:\项目\RemotingHello\HelloClient\App.config 5 8 HelloClient
    消息 3 未能找到元素“wellknown”的架构信息。 D:\项目\RemotingHello\HelloClient\App.config 6 10 HelloClient
    消息 4 未能找到属性“type”的架构信息。 D:\项目\RemotingHello\HelloClient\App.config 6 20 HelloClient
    消息 5 未能找到属性“url”的架构信息。 D:\项目\RemotingHello\HelloClient\App.config 6 63 HelloClient
    消息 6 未能找到元素“channels”的架构信息。 D:\项目\RemotingHello\HelloClient\App.config 8 8 HelloClient
    消息 7 未能找到元素“channel”的架构信息。 D:\项目\RemotingHello\HelloClient\App.config 9 10 HelloClient
    消息 8 未能找到属性“ref”的架构信息。 D:\项目\RemotingHello\HelloClient\App.config 9 18 HelloClient
    消息 9 未能找到属性“displayName”的架构信息。 D:\项目\RemotingHello\HelloClient\App.config 9 28 HelloClient
    消息 10 未能找到元素“application”的架构信息。 D:\项目\RemotingHello\HelloServer\App.config 4 6 HelloServer
    消息 11 未能找到元素“service”的架构信息。 D:\项目\RemotingHello\HelloServer\App.config 5 8 HelloServer
    消息 12 未能找到元素“wellknown”的架构信息。 D:\项目\RemotingHello\HelloServer\App.config 6 10 HelloServer
    消息 13 未能找到属性“type”的架构信息。 D:\项目\RemotingHello\HelloServer\App.config 6 20 HelloServer
    消息 14 未能找到属性“mode”的架构信息。 D:\项目\RemotingHello\HelloServer\App.config 6 63 HelloServer
    消息 15 未能找到属性“objectUri”的架构信息。 D:\项目\RemotingHello\HelloServer\App.config 6 81 HelloServer
    消息 16 未能找到元素“channels”的架构信息。 D:\项目\RemotingHello\HelloServer\App.config 8 8 HelloServer
    消息 17 未能找到元素“channel”的架构信息。 D:\项目\RemotingHello\HelloServer\App.config 9 10 HelloServer
    消息 18 未能找到属性“ref”的架构信息。 D:\项目\RemotingHello\HelloServer\App.config 9 18 HelloServer
    消息 19 未能找到属性“port”的架构信息。 D:\项目\RemotingHello\HelloServer\App.config 9 28 HelloServer
    消息 20 未能找到属性“displayName”的架构信息。 D:\项目\RemotingHello\HelloServer\App.config 9 40 HelloServer
      

  10.   

    服务器是跑起来了
    可是用new创建立的对象却是本地的实例,不是服务器上的对象,百思不得其解.
    等待高手.
      

  11.   

    //如下是server配置文件
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.runtime.remoting>
        <application name="CallbackSample">
          <service>
            <activated type="RemoteObject.remote,RemoteObject"></activated>
            <activated type="RemoteObject.SinkEvent,RemoteObject"></activated>
          </service>
          <channels>
            <channel ref="tcp" port="888">
               <serverProviders>
                 <provider ref="wsdl" />
                 <formatter ref="soap" typeFilterLevel="Full" />
                  <formatter ref="binary" typeFilterLevel="Full" />
               </serverProviders>
            </channel>
          </channels>
        </application>
      </system.runtime.remoting>
    </configuration> 如下是client配置文件
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.runtime.remoting>
        <application name="Client">
          <client url="tcp://localhost:888/hi">
            <activated type="RemoteObject.remote,RemoteObject"></activated>
            <activated type="RemoteObject.SinkEvent,RemoteObject"></activated>
            <channels>
              <channel ref="tcp" port="0">
                <serverProviders>
                  <provider ref="wsdl" />
                  <formatter ref="soap" typeFilterLevel="Full" />
                  <formatter ref="binary" typeFilterLevel="Full" />
                </serverProviders>
              </channel>
            </channels>
          </client>
        </application>
      </system.runtime.remoting>
    </configuration>
      

  12.   

    问题解决,原来是自已粗心,错将<channel>元素当作<client>的子元素
    还有就是XML语法上的错误,<channel ref="" />闭符号的时候要留一下空格
    晕死~~~