I am using C# .net remoting and am trying to store xml data in an arraylist and call the method in the client class.
When i try to execute my code i get message saying: object reference not set to an instance of an object.
Here is my code: (Object Class)
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Collections;
namespace UseXML
{
public class UseXML : MarshalByRefObject
{
public ArrayList list()
{
ArrayList array = new ArrayList();
try
{
XmlTextReader xReader = new XmlTextReader(@"../Games.xml");
XmlDocument doc = new XmlDocument();
doc.Load(xReader);
XmlElement root = doc.DocumentElement;
XmlNodeList list = root.SelectNodes("//Games/Game");
foreach (XmlNode n in list)
{
string sm = n["name"].InnerText + "\n" + n["amount"].InnerText;
array.Add(sm);
}
return array;
}
catch (Exception e)
{
return null;
}
}
}
}
Server Class:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace ServerClass
{
class Program
{
static void Main(string[] args)
{
TcpChannel channel = new TcpChannel(1973);
ChannelServices.RegisterChannel(channel, true);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(UseXML.UseXML), "UseXML", WellKnownObjectMode.SingleCall);
Console.WriteLine("Server Running....");
}
}
}
Client class:
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using UseXML;
namespace ClientClass
{
class Program
{
static void Main(string[] args)
{
TcpChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel, true);
Console.WriteLine("Welcome to games");
Console.WriteLine();
Console.WriteLine("[1] Display All games");
Console.WriteLine("[2] Display select game");
Console.WriteLine("[3] Exit");
Console.WriteLine();
Console.WriteLine("Enter your choice");
int input = Int32.Parse(Console.ReadLine());
UseXML.UseXML useX;
try
{
useX = (UseXML.UseXML)Activator.GetObject(typeof(UseXML.UseXML), "tcp://localhost:8085/UseXML");
useX = new UseXML.UseXML();
ArrayList list = useX.list();
while (input < 3)
{
if (input == 1)
{
for (int i = 0; i < list.Count; i++)
{
Console.WriteLine(list[i]);
}
}
else if (input == 2)
{
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
When run the project and press 1, all the games in the xml file should be retrieved. Please help...