|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
.NET RemotingHi guys,
I'm developing a distributed application in C#, where I want to use .NET Remoting, but there's problem with it. Everything works fine when I call remote procedure with parameters of standard types, like string, int, bool,... But if I want to send an own object, I get the error: "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object" I tried to use an HttpChannel and also TcpChannel but the problem is somewhere else. I found an example that works when I use dll-s. //////////////////////////// THIS IS SERVER: <<<<Main.cs>>>>> HttpServerChannel httpchannel = new HttpServerChannel(8085); ChannelServices.RegisterChannel(httpchannel); RemotingConfiguration.RegisterWellKnownServiceType(typeof(nsCRemoteObj.CRemoteObj), "CRemoteObjURI", WellKnownObjectMode.SingleCall ); /////////////////////////// THIS IS CLIENT: <<<<Main.cs>>>> ChannelServices.RegisterChannel( new HttpChannel() ); IRemoteObj obj = (IRemoteObj) Activator.GetObject( typeof(IRemoteObj), "http://localhost:8085/CRemoteObjURI" ); //calling remote procedure Node node = new Node("127.0.0.1",12345); Node nout = obj.TestMethod(node); Console.WriteLine("TestMethod completed. Returned ip: {0}", nout.ipAdd); ///////////////////////////////// MY REMOTE CLASS: <<<CRemoteObj.cs>>> public class CRemoteObj : System.MarshalByRefObject, IRemoteObj { public CRemoteObj() { Console.WriteLine("CRemoteObj constructor invoked."); } ~CRemoteObj() { Console.WriteLine("CRemoteObj destructor invoked."); } // definition of our method(s) public Node TestMethod(Node node) { Console.WriteLine("CRemoteObj.TestMethod invoked."); Console.WriteLine("Ip Address = {0}, Port = {1}", node.ipAdd, node.po); Node nout = node; nout.ipAdd = "manager"; return nout; } } ///////////////////////// AND INTERFACE (includes my own object): <<<IRemoteObj.cs>>> // custom object which we want to pass [Serializable] public class Node { public string ipAdd; public int po; public Node() { } public Node(string ipAddress, int port) { ipAdd = ipAddress; po = port; } }; // interface which contains declaration of our method(s) public interface IRemoteObj { Node TestMethod(Node node); } ///////////////////////////////////////////////// That should work. But it doesn't, only when I make DLL files from Remote Class (CRemoteObj.cs) and Interface (IRemoteObj.cs). And then I must include these DLL files into my server and client. I believe that this can work without DLL but I don't how, so if anyone has any idea, please help me. I will really appreciate it, I cannot go forward because of this. I don't want to use DLL files. Thanx for any help. |
|
|
Re: .NET RemotingYsgrifennodd nemesis35:
> Hi guys, > > I'm developing a distributed application in C#, where I want to use .NET > Remoting, but there's problem with it. > Does this help? http://www.peredur.uklinux.net/Remoting.pdf If I understand your problem correctly, it has to do with the fact that both the client and server have to have a definition of the type you are trying to pass. I've not read your post in great detail, though, so I could be wrong. Peter _______________________________________________ Mono-list maillist - Mono-list@... http://lists.ximian.com/mailman/listinfo/mono-list |
|
|
Re: .NET Remotingnemesis35 wrote:
> ///////////////////////////////////////////////// > That should work. But it doesn't, only when I make DLL files from Remote > Class (CRemoteObj.cs) and Interface (IRemoteObj.cs). And then I must include > these DLL files into my server and client. > > I believe that this can work without DLL but I don't how, so if anyone has > any idea, please help me. I will really appreciate it, I cannot go forward > because of this. I don't want to use DLL files. The short answer is: it cannot work w/out a shared dll, because when the interfaces are compiled in both assemblies, their identities are not the same anymore. The interfaces will be treated as 2 distinct incompatible types. If you don't like this, you have to drop the interfaces at all and use stubs generated by the "soapsuds" tool (delivered with mono and MS.NET). It's not worthwhile. Robert _______________________________________________ Mono-list maillist - Mono-list@... http://lists.ximian.com/mailman/listinfo/mono-list |
| Free embeddable forum powered by Nabble | Forum Help |