开发者

Remoting in C# not working

开发者 https://www.devze.com 2022-12-20 23:50 出处:网络
I am learning about using Remoting in .NET. I have built a small application which does a basic hello world work.

I am learning about using Remoting in .NET. I have built a small application which does a basic hello world work. the code for RemoteObject is :

public class MyRemoteObjectClass:MarshalByRefObject
    {
        public MyRemoteObjectClass()
        {
            Console.WriteLine("Remote object created");
        }
        //return message reply
        public String ReplyMessage(String msg)
        {
            Console.WriteLine("Client : " + msg);//print given message on console 
            return "Server : Yeah! I'm here";
        }
    }

The code for server class is:

class MyServerClass
    {
        public MyServerClass()
        {
        }
        static void Main(string[] args)
        {
            RemotingConfiguration.Configure("RemotingSettings_Server.xml",false);
            Console.WriteLine("server activated");
            Console.ReadLine();
        }
    }

The source code for client class is:

class MyClientAppClass
    {
        static void Main(string[] args)
        {
            RemotingConfiguration.Configure("ClientSettings.xml",false);
            Console.WriteLine("Settings read successfully");
            MyRemoteObjectClass remObject = (MyRemoteObjectClass)Activator.GetObject(typeof(MyRemoteObject.MyRemoteObjectClass),"http://localhost:8989/MyRemoteObjectClass",WellKnownObjectMode.Singleton);
            if (remObject == null)
                Console.WriteLine("cannot locate server");
            else
            { String res = remObject.ReplyMessage("You there?"); Console.WriteLine(res); Console.ReadLine(); }

        }
    }

My config files for server and client respectively are:

<configuration>
   <system.runtime.remoting>
      <application>
         <service>
            <wellknown 
               mode="Singleton" 
               type="MyRemoteObject.MyRemoteObjectClass, MyRemoteObjectClass" 
               objectUri="MyRemoteObjectClass.rem"
            />
         </service>
         <channels>
            <channel ref="http" port="8989"/>
         </channels>
      </application>
   </system.runtime.remoting>
</configuration>

client:

<configuration>
  <system.runtime.remoting>
    <application>
      <client>
        <wellknown
           type="MyRemoteObject.MyRemoteObjectClass, MyRemoteObjectClass"
           url="http://localhost:8989/MyRemoteObjectClass.rem"
            />
      </client>
    </application>
  </system.runtime.remoting>
</configuration>

I first built the DLL for the remote object, copied the DLL in both server and client exe locations. I ran server then and then ran client. Server is instantiated but client program thtows exception saying "Remoting Exception:Requested service not found".

Please help me solve this and may be a good place to learn the remoting 开发者_如何学Goconcepts clearly.

Thanks, Rakesh.


Check out your configuration file - it is case sensitive. "objecturi" should be "objectUri", for example.


Deactivate your firewall. If it then works, reactivate the firewall and add the appropriate exception.

0

精彩评论

暂无评论...
验证码 换一张
取 消