Client server spm
Jeg forsøget at lave an simple client server. Sådan:using System;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
namespace Wrox.ProCshap.Remoting
{
public class HelloClient
{
public static void Main(string[] args)
{
ChannelServices.RegisterChannel(new HttpClientChannel());
HelloClient obj = (HelloClient)Activator.GetObject(typeof(HelloClient), "http://localhost:8086/Hi");
if (obj ==null)
{Console.WriteLine("could not locate server");
return;
}
for (int i=0; i<5;i++)
{Console.WriteLine("Lars..");
}
}
}
}
---------------------------------
Men jeg få fejl ved
HelloClient obj = (HelloClient)Activator.GetObject(typeof(HelloClient), "http://localhost:8086/Hi");
den viser ovenstående og siger exception arised.
-----------------------------------------------
Serveren ser sådan ud
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace ServerApplication
{
class HelloServer
{
public static void Main(string[] args)
{
TcpServerChannel channel = new TcpServerChannel(8086);
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(HelloServer), "Hi", WellKnownObjectMode.SingleCall);
System.Console.WriteLine("Press an key to return");
System.Console.ReadLine();
}
}
}