Remoting in C#
Hi to all members
My problem is related to remoting in c#. there are three files
c.cs Customer file code
s.cs Server File Code
o.c Server side code which we call in C.CS
C.CS File
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
public class ccc
{
public static void Main()
{
TcpChannel c = new TcpChannel();
ChannelServices.RegisterChannel(c);
zzz a = (zzz)Activator.GetObject(typeof(zzz), "tcp://localhost:8085/eee");
if (a == null)
System.Console.WriteLine("Could not locate server");
else
Console.WriteLine(a.abc());
}
}
S.CS
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
public class sss
{
public static void Main()
{
TcpChannel c = new TcpChannel(4444);
ChannelServices.RegisterChannel(c,true);
RemotingConfiguration.RegisterWellKnownServiceType (
Type.GetType("zzz,o"), "eee", WellKnownObjectMode.SingleCall);
System.Console.WriteLine("Press <enter> to exit...");
System.Console.ReadLine();
}
}
O.CS
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
public class zzz : MarshalByRefObject
{
public zzz()
{
Console.WriteLine("Constructor");
}
~zzz()
{
Console.WriteLine("Destructor");
}
public String abc()
{
Console.WriteLine("Vijay Mukhi2");
return "Sonal";
}
}
When I Comple and execute . itâs compile properly but not execute client code.
Server class execute successfully and give
o/p Press <enter> to exit...
when I execute client code itâs this error
Unhandled Exception: System.Net.Sockets.SocketException: No connection could be
made because the target machine actively refused it 127.0.0.1:8085
Server stack trace:
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddre
ss socketAddress)
at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
at System.Runtime.Remoting.Channels.RemoteConnection. CreateNewSocket(EndPoint
ipEndPoint)
at System.Runtime.Remoting.Channels.RemoteConnection. CreateNewSocket()
at System.Runtime.Remoting.Channels.SocketCache.GetSo cket(String machinePortA
ndSid, Boolean openNew)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTran sportSink.SendRequestWit
hRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTran sportSink.ProcessMessage
(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITranspor
tHeaders& responseHeaders, Stream& responseStream)
at System.Runtime.Remoting.Channels.BinaryClientForma tterSink.SyncProcessMess
age(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleRe turnMessage(IMessage req
Msg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateI nvoke(MessageData& msgDa
ta, Int32 type)
at zzz.abc()
at ccc.Main()
My Problem : I am not getting which port I can use for remoting please help me to solve this problem
Thanks
mahendra singh
|