[Mono-devel-list] Fail in remoting object

gaston acuse gastonacuse at yahoo.com.ar
Sun Sep 5 18:59:37 EDT 2004


This is a simple example of remoting. But make an
exception and I don't know why.
Any body can help me?
Thanks in advance.
Gaston.

//********* the client 
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using RemotingExampleInterfaces;

namespace RemotingExampleClient
{
  class RemotingExampleClient
  {
    static void Main(string[] args)
    {
      ChannelServices.RegisterChannel(new
TcpClientChannel());
      IRemotingExampleService resService
=(IRemotingExampleService)Activator.GetObject(
        typeof(IRemotingExampleService),
       
"tcp://localhost:9988/RemotingExampleService");
      Console.WriteLine("RESUME:\n"+
resService.GetFormattedResume());
      Console.WriteLine("1\n");
      IResume aResume = resService.GetResume();
      Console.WriteLine("2\n");
      string tmp = aResume.GetFormattedName();
      Console.WriteLine("21\n");
      Console.WriteLine("NAME:"+ tmp);
      Console.WriteLine("3\n");
      Console.WriteLine("RESUME:"+
aResume.GetFormattedResume());
      Console.WriteLine("Press any key to
continue...");
      Console.Read();
    }
  }
}


//*************** the server
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using RemotingExampleInterfaces;
using System.Runtime.Serialization;

namespace RemotingInterfaceServer
{
  public class EntryPoint
  {
    public static void Main(string[] args)
    {
      TcpServerChannel channel = new
TcpServerChannel(9988);
      ChannelServices.RegisterChannel(channel);
     
RemotingConfiguration.RegisterWellKnownServiceType(
          typeof(RemotingExampleService),
          "RemotingExampleService",
WellKnownObjectMode.SingleCall);
      System.Console.WriteLine("Press Any Key");
      System.Console.ReadLine();
    }
  }

  public class RemotingExampleService :
MarshalByRefObject, IRemotingExampleService
  {
    public RemotingExampleService() {}

    public IResume GetResume()
    {
      Resume resume = new Resume();
      resume.FirstName="David";
      resume.LastName="Talbot";
      resume.Title="Senior Software Architect";
      resume.Body="Did some cool stuff";
      return (IResume)resume;
    }

    public String GetFormattedResume()
    {
      return GetResume().GetFormattedResume();
    }
  }

  [Serializable]
  public class Resume : MarshalByRefObject, IResume
  {
    public String FirstName, LastName, Body, Title;

    public String GetFormattedResume()
    {
      System.Text.StringBuilder sb = new
System.Text.StringBuilder();
      sb.Append("*"+ GetFormattedName() +"*\n");
      sb.Append("--"+ Title +"--\n");
      sb.Append("--------------------------\n");
      sb.Append(Body);
      return sb.ToString();
    }

    public String GetFormattedName()
    {
    Console.WriteLine("Resume.GetFormattedName\n");
     return FirstName +" "+ LastName;
    }
  }//END OF Resume Object
}


//************* the interface
using System;

namespace RemotingExampleInterfaces
{

        public interface IResume
        {
                String GetFormattedResume();
                String GetFormattedName();
        }

        public interface IRemotingExampleService
        {
                IResume GetResume();
                String GetFormattedResume();
        }
}



// ************** how to compile 
mcs -r:System.Runtime.Remoting.dll -t:library
interface.cs
mcs -r:System.Runtime.Remoting.dll -r:interface.dll
server.cs
mcs -r:System.Runtime.Remoting.dll -r:interface.dll
client.cs



//**************** when run,  the server session show:
Press Any Key
Resume.GetFormattedName

//***************** when run, the client session show:
ga at linux:~/
ga at linux:~/develop/remoting-good-object> mono
client.exe
RESUME:
*David Talbot*
--Senior Software Architect--
--------------------------
Did some cool stuff
1

2


Unhandled Exception:
System.Runtime.Remoting.RemotingException: Network is
unreachable

Server stack trace:
in <0x000f2>
System.Runtime.Remoting.Channels.Tcp.HostConnectionPool:CreateConnection
()
in <0x00132>
System.Runtime.Remoting.Channels.Tcp.HostConnectionPool:GetConnection
()
in <0x00117>
System.Runtime.Remoting.Channels.Tcp.TcpConnectionPool:GetConnection
(string,int)
in <0x00155>
System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink:ProcessMessage
(System.Runtime.Remoting.Messaging.IMessage,System.Runtime.Remoting.Channels.ITransportHeaders,System.IO.Stream,System.Runtime.Remoting.Channels.ITransportHeaders&,System.IO.Stream&)
in <0x002e3>
System.Runtime.Remoting.Channels.BinaryClientFormatterSink:SyncProcessMessage
(System.Runtime.Remoting.Messaging.IMessage)


Exception rethrown at [0]:

in <0x00601>
System.Runtime.Remoting.Proxies.RealProxy:PrivateInvoke
(System.Runtime.Remoting.Proxies.RealProxy,System.Runtime.Remoting.Messaging.IMessage,System.Exception&,object[]&)
develop/remoting-good-object> mono server.exe

//***************** that's all******************






Correo Yahoo! - 6 MB, tecnología antispam ¡gratis! 
 Suscribite ya http://correo.yahoo.com.ar/



More information about the Mono-devel-list mailing list