[Mono-list] Remoting

Wilhelm Patrick Patrick.Wilhelm@khe.siemens.de
Tue, 5 Aug 2003 12:19:46 +0200


Hi!

> Lluis Sanchez wrote:
> 
> [snip]
> > under windows everything work's fine, 
> 
> using MS.NET or Mono in Windows?

I'm using MS.NET.

> The error is that you need to register the TcpChannel in the 
> client. In
> the code you sent it is not registered. Maybe are you using a
> configuration file? Notice that remoting configuration files 
> do not yet
> work in mono.

I don't use a configuration file. Ok, I'v correctet the code, but now I get
another error. for testing I wrote a small console app:

using System;
using System.Runtime.Remoting;
#if USE_HTTP
using System.Runtime.Remoting.Channels.Http;
#endif
#if USE_TCP
using System.Runtime.Remoting.Channels.Tcp;
#endif
using System.Runtime.Remoting.Channels;

	class MainClass
	{
    enum AppMode 
    {
      Client,
      Server
    }

    static AppMode appMode;


		[STAThread]
		static void Main(string[] args)
		{

      // check for command line arguments
      ParseArgs(args);
      // start server or client
#if USE_HTTP
      Console.WriteLine("Using http channel");
#endif
#if USE_TCP
      Console.WriteLine("Using tcp channel");
#endif
      Init();

		}

    static void ParseArgs(string []args) 
    {
      // set the standard appMode to server
      // (if not set with parameters)
      appMode = AppMode.Server;
      for (int i=0; i<args.GetLength(0); i++) 
      {
        if (args[i].CompareTo("-server") == 0)
          appMode = AppMode.Server;
        else if (args[i].CompareTo("-client") == 0)
          appMode = AppMode.Client;
      }
    }

      static void Init()
      {
        switch (appMode)
        {
          case AppMode.Client:
            Client.Connect();
            break;
          case AppMode.Server:
            Listener.GoListening();
            break;
          default:
            break;
        }
      }
	}

public class Listener
  {
    public static void GoListening()
    {
      //RemotingConfiguration.Configure("Listener.exe.config");
      #if USE_TCP
      ChannelServices.RegisterChannel(new TcpChannel(8989));
      #endif
      #if USE_HTTP
      ChannelServices.RegisterChannel(new HttpChannel(8989));
      #endif

      WellKnownServiceTypeEntry WKSTE = new WellKnownServiceTypeEntry(
        typeof(RemotableType),
        "RemotableType.rem", WellKnownObjectMode.SingleCall);
      RemotingConfiguration.ApplicationName = "RemotingTestServer";
      RemotingConfiguration.RegisterWellKnownServiceType(WKSTE);

 
//RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotableType),"
RemotableType.rem",WellKnownObjectMode.Singleton);
      //ChannelServices.RegisterChannel(new HttpChannel(8989));

      Console.WriteLine("Listening for requests. Press Enter to exit...");
      Console.ReadLine();
    }
  }

  public class Client
  {

    public static void Connect()
    {
#if USE_HTTP
      ChannelServices.RegisterChannel(new HttpChannel());
#endif
#if USE_TCP
      ChannelServices.RegisterChannel(new TcpChannel());
#endif

#if USE_TCP
      WellKnownClientTypeEntry WKCTE = new WellKnownClientTypeEntry(
        typeof(RemotableType),
        "tcp://localhost:8989/RemotingTestServer/RemotableType.rem");
#endif
#if USE_HTTP
      WellKnownClientTypeEntry WKCTE = new WellKnownClientTypeEntry(
        typeof(RemotableType),
        "http://localhost:8989/RemotingTestServer/RemotableType.rem");
#endif

      RemotingConfiguration.RegisterWellKnownClientType(WKCTE);

      RemotableType remoteObject = new RemotableType();
      Console.WriteLine(remoteObject.RemoteString);
      remoteObject.WriteToServerConsole("Hallo dieser Text kommt vom
Client");
    }
  }

  public class RemotableType : MarshalByRefObject
  {
    private string _internalString = "This text comes from the RemotableType
on the server.";
    
    public string RemoteString
    {
      get
      {
        return _internalString;
      }
    }

    public void WriteToServerConsole(string sText)
    {
      Console.WriteLine(sText);
    }
  }

############################################################################
#######

When I use tcp I get the following error on client end:
Using tcp channel

Unhandled Exception: System.Runtime.Remoting.RemotingException: Unknown
response message from server

Server stack trace:
in <0x000ce> 00
System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink:ProcessMessage
(System.Runtime.Remoting.Messaging.IMessage,System.Runtime.Remoting.Channels
.ITransportHeaders,System.IO.Stream,System.Runtime.Remoting.Channels.ITransp
ortHeaders&,System.IO.Stream&)
in <0x001be> 00
System.Runtime.Remoting.Channels.BinaryClientFormatterSink:SyncProcessMessag
e (System.Runtime.Remoting.Messaging.IMessage)


Exception rethrown at [0]:

in <0x000ab> 00 System.Runtime.Remoting.Proxies.RealProxy:PrivateInvoke
(System.Runtime.Remoting.Proxies.RealProxy,System.Runtime.Remoting.Messaging
.IMessage,System.Exception&,object[]&)
in (unmanaged) 07 NRemotingType.RemotableType:get_RemoteString ()
in <0x00004> 07 NRemotingType.RemotableType:get_RemoteString ()
in <0x0002f> 08 NRemotingType.RemotableType:get_RemoteString ()
in <0x00092> 00 NRemotingTestClient.Client:Connect ()
in <0x00029> 00 NRemotingTestApp.MainClass:Init ()
in <0x0001f> 00 NRemotingTestApp.MainClass:Main (string[])

############################################################################
#######

When I use http I get the following error on client end:
Using http channel
System.Net.WebException: The request timed out
in <0x001b6> 00 System.Net.HttpWebRequest:EndGetResponse
(System.IAsyncResult)
in <0x00096> 00 System.Net.HttpWebRequest:GetResponse ()
in <0x00040> 00
System.Runtime.Remoting.Channels.Http.HttpClientTransportSink:SendAndRecieve
(System.Net.HttpWebRequest,System.Runtime.Remoting.Channels.ITransportHeader
s&,System.IO.Stream&)


Unhandled Exception: System.ArgumentNullException: Argument cannot be null
Parameter name: serializationStream is null

Server stack trace:
in <0x0003f> 00
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter:DeserializeMe
thodResponse
(System.IO.Stream,System.Runtime.Remoting.Messaging.HeaderHandler,System.Run
time.Remoting.Messaging.IMethodCallMessage)
in <0x00202> 00
System.Runtime.Remoting.Channels.BinaryClientFormatterSink:SyncProcessMessag
e (System.Runtime.Remoting.Messaging.IMessage)


Exception rethrown at [0]:

in <0x000ab> 00 System.Runtime.Remoting.Proxies.RealProxy:PrivateInvoke
(System.Runtime.Remoting.Proxies.RealProxy,System.Runtime.Remoting.Messaging
.IMessage,System.Exception&,object[]&)
in (unmanaged) 07 NRemotingType.RemotableType:get_RemoteString ()
in <0x00004> 07 NRemotingType.RemotableType:get_RemoteString ()
in <0x0002f> 08 NRemotingType.RemotableType:get_RemoteString ()
in <0x00092> 00 NRemotingTestClient.Client:Connect ()
in <0x00029> 00 NRemotingTestApp.MainClass:Init ()
in <0x0001f> 00 NRemotingTestApp.MainClass:Main (string[])

############################################################################
#######
On Windows with ms.NET I don't get any errors. (in both modes: http and tcp)

What's wrong? Hope you can help me! Thank you!

SIEMENS AG
Patrick Wilhelm
A&D SE DT RD
Siemensallee 84
D-76181 Karlsruhe, Germany

Email: patrick.wilhelm@khe.siemens.de
<mailto:patrick.wilhelm@khe.siemens.de>
Tel.:  +49 (721) 595 3075