Cześć, mam następujący problem. Chcę stworzyć aplikację klient-serwer (uczę się), ale gdy próbuję wywołać konstruktor niestandardowy dla typu zarejestrowanego jako CAO, otrzymuje błąd: "An unhandled exception of type 'System.Net.WebException' occurred in mscorlib.dll. Additional information: Nie można połączyć się z serwerem zdalnym".
Pakiet ogólny:
public class JamesBondCar : Car
{
public bool IsFlightWorthy;
public bool IsSealWorthy;
public JamesBondCar() { }
public JamesBondCar(string petName, int maxSpeed, bool canFly, bool canSubmerge)
: base(petName, maxSpeed)
{
this.IsFlightWorthy = canFly;
this.IsSealWorthy = canSubmerge;
}
public void Fly()
{
if (IsFlightWorthy)
MessageBox.Show("Odlatuję!!");
else
MessageBox.Show("Nigdzie nie lecę...");
}
public void GoUnderWater()
{
if (IsSealWorthy)
MessageBox.Show("Zanurzam się !!");
else
MessageBox.Show("Nigdzie sie nie zanurzam!");
}
}
public class CarProvider : MarshalByRefObject
{
private ArrayList theJBCars = new ArrayList();
public CarProvider()
{
Console.WriteLine("Utworzono CarProvider.");
theJBCars.Add(new JamesBondCar("QMobile", 140, true, true));
theJBCars.Add(new JamesBondCar("FLyer", 140, true, false));
theJBCars.Add(new JamesBondCar("Swimmer", 140, false, true));
theJBCars.Add(new JamesBondCar("BasicJBC", 140, false, false));
}
public CarProvider(JamesBondCar[] theCars)
{
Console.WriteLine("Utworzono JamesBondCar za pomocą niestandardowego konstruktora.");
theJBCars.AddRange(theCars);
}
public ArrayList GetAllAutos()
{ return theJBCars; }
public JamesBondCar GetJBCByIndex(int i)
{ return (JamesBondCar)theJBCars[i]; }
}
Pakiet serwera:
namespace CarProviderServer
{
public class CarServer
{
static void Main(string[] args)
{
RemotingConfiguration.Configure("CarProviderServer.exe.config",false);
Console.WriteLine("**** Aplikacja serwera dla wypróbowania typów CAO ****");
Console.WriteLine("Wciśnij ENTER, by zakmnąć serwer...");
Console.ReadLine();
}
}
}
Plik App.config dla serwera:
<configuration>
<system.runtime.remoting>
<application>
<service>
<activated
type="CarGeneralAsm.CarProvider,CarGeneralAsm"/>
</service>
<channels>
<channel ref="http" port="32469"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>
Pakiet klienta:
namespace CarProviderClient
{
class CarClient
{
static void Main(string[] args)
{
RemotingConfiguration.Configure("CarProviderClient.exe.config",false);
//RemotingConfiguration.RegisterActivatedClientType(typeof(CarGeneralAsm.CarProvider), "http://localhost:32469");
Console.WriteLine("**** Aplikacja {0} wystartowała! ****", RemotingConfiguration.ApplicationName);
Console.WriteLine("Wciśniej ENTER, by zamknąć okno klienta.\n");
JamesBondCar[] cars = { new JamesBondCar("one", 100, true, true),
new JamesBondCar("Two", 100, true, true),
new JamesBondCar("Three", 100, true, true) };
CarProvider cp = new CarProvider(cars);
Console.ReadLine();
}
}
}
Plik App.config dla klienta:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application name="TestowanieTypówCAO">
<client
url="http://localhost:32469">
<activated
type="CarGeneralAsm.CarProvider,CarGeneralAsm"/>
</client>
<channels>
<channel ref="http"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>
Gdyby ktoś mógł mi pomóc, będę niezmiernie wdzięczny.