« Return to Thread: .NET Remoting

.NET Remoting

by nemesis35 :: Rate this Message:

Reply to Author | View in Thread

Hi 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.

 « Return to Thread: .NET Remoting