I'm currently testing several ways to have one application get hold of an object from another application. Both are written in C# and wether I use IPC channels or WCF Service Contracts I end up with the same problem. If I use a simple class whose properties and methods only return the built in types (such as int, string or ArrayList) it works fine, but if I add another property of a custom made type I get an error. IPC gives me a InvalidCastException and WCF puts the channel in a Faulted state and it breaks. Obviously I'm doing something wrong and I hope someone can give me a hand. The server looks like this:
public interface IBase {<br /><br /> int IntTest { get; }<br /> String StringTest { get; }<br /> IOther OtherTest { get; }<br /><br /> String Test(String txt);<br /> IOther Test3();<br />}<br /><br />public interface IOther {<br /> String StringTest { get; }<br /> String Test(String txt);<br />}<br /><br />public class Base : MarshalByRefObject, IBase {<br /><br /> public int IntTest {<br /> get { return 4; }<br /> }<br /><br /> public string StringTest {<br /> get { return "A string from Base"; }<br /> }<br /><br /> public IOther OtherTest {<br /> get { return new Other(); }<br /> }<br /><br /> public string Test(string txt) {<br /> return "Base called with: " + txt;<br /> }<br /><br /> public IOther Test3() {<br /> return new Other();<br /> }<br /><br />}<br /><br />public class Other : MarshalByRefObject, IOther {<br /><br /> public string StringTest {<br /> get { return "A string from Other"; }<br /> }<br /><br /> public string Test(string txt) {<br /> return "Other method called with: " + txt;<br /> }<br /><br />}
The server is registered like this:
public MainWindow() {<br /> InitializeComponent();<br /> IpcChannel ipcCh = new IpcChannel("IPChannelName");<br /> ChannelServices.RegisterChannel(ipcCh, false);<br /> RemotingConfiguration.RegisterWellKnownServiceType(typeof(Base), "CName", WellKnownObjectMode.Singleton);<br />}
The client looks something like this:
IpcChannel ipcCh = new IpcChannel("myClient");<br />ChannelServices.RegisterChannel(ipcCh, false);<br />obj = (IBase)Activator.GetObject(typeof(IBase), "ipc://IPChannelName/CName");<br />Console.WriteLine("Returns: " + obj.Test("a text"));<br />Console.WriteLine("Returns: " + obj.StringTest + " " + obj.StringTest.Length);<br />Console.WriteLine("Returns: " + obj.IntTest);<br />Console.WriteLine(obj.OtherTest.ToString());
The last line gives me the InvalidCastException or, in the cae of WCF, the Faulted pipe. Please help.