Lately I've been playing with the shared source implementation of the Microsoft .NET Framework (SSCLI). I downloaded and built it a while back, but it didn't become fun until I read Jason Whittington's article in the July MSDN Magazine. He passes on a technique for easily getting the whole runtime into the Visual Studio debugger, where you can set breakpoints and use all the usual debugging techniques.
Looking over the directories in the distribution, I noticed that several remoting classes were included. In an exercise in jumping in at the deep end, I decided to follow up my "Hello World" experiment with a little HTTP remoting sample.
I built an interface:
public interface IEcho
{
void repeatAfterMe(string s);
}
and a server:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
public class Echo : MarshalByRefObject, IEcho
{
public Echo()
{
Console.WriteLine("Echo constructed");
}
public void repeatAfterMe(string s)
{
Console.WriteLine("Repeating... {0}",s);
}
}
public class MyServer
{
public static int Main(string[] args)
{
HttpChannel chan = new HttpChannel(1234);
ChannelServices.RegisterChannel(chan);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(Echo),"myecho",WellKnownObjectMode.Singleton);
System.Console.WriteLine("Hit to exit...");
System.Console.ReadLine();
return 0;
}
} and a client:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
public class Client
{
public static int Main(string [] args)
{
HttpChannel chan = new HttpChannel(998);
ChannelServices.RegisterChannel(chan);
Object obj = RemotingServices.Connect(
typeof(IEcho),"http://localhost:1234/myecho");
try
{
((IEcho)obj).repeatAfterMe("Hi there");
}
catch (System.Exception e)
{
Console.WriteLine("Failed to connect to or call server");
Console.WriteLine(e.Message);
}
return 0;
}
} I compiled the three files from the command line like so:
csc /t:library echoif.cs
csc /r:echoif.dll /r:System.Runtime.Remoting.dll server.cs
csc /r:echoif.dll /r:System.Runtime.Remoting.dll client.cs
The server runs error-free (using clix, the SSCLI launcher), but the client fails with this error message:
!"ECall methods must be packaged into a system module,
such as MSCOREE.DLL" I can run the client in the normal .NET framework against the SSCLI server with no problem, as long as I use the versions built with the SSCLI. (The versions built with the release framework work fine with it, of course). Next step, to look at the IL and see if I can figure out what's going on. This is what I do for fun!
[Later... The SSCLI team at Microsoft has a fix for this problem. I'm sure it will be available soon in a future release]
4:23:49 PM
|