I am trying to create a remoting application to which I don't want the client to know anything about the implementation but just the interfaces. On the server side, it will load the implementation dll by using Assembly. The problem with this code is that when I run the application, the client will successfully get the remote object however when I try to call the method from it (also defined inside the interfaces), an exception is thrown (i.e. FileNotFoundException). I am not sure what to do, can you guys help me with this.?
Interfaces
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespaceInterfaces
{
publicinterfaceICustomer
{
voidsetName(string name);
stringgetName();
}
}
Implementation
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Interfaces;
namespaceImplementation
{
publicclassCustomer : MarshalByRefObject, ICustomer
{
string name;
publicCustomer()
{
name = "harris";
}
publicvoidsetName(string name)
{
this.name = name;
}
publicstringgetName()
{
return name;
}
}
}
Server
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Reflection;
namespaceServer
{
classProgram
{
staticvoidMain(string[] args)
{
System.Reflection.Assembly newAssembly = System.Reflection.Assembly.LoadFrom(@"C:\Documents and Settings\BP FANTONI\Desktop\RemotingApp3\Implementation\bin\Debug\Implementation.dll");
Object o = newAssembly.CreateInstance("Implementation.Customer");
//Assembly a = Assembly.LoadFrom("C:\\Documents and Settings\\BP FANTONI\\Desktop\\RemotingApp3\\Implementation\\bin\\Debug\\Implementation.dll");//Module m = newAssembly.GetModule("Implementation.dll");
Type t = o.GetType();
System.Runtime.Remoting.Channels.Tcp.TcpServerChannel channel = new System.Runtime.Remoting.Channels.Tcp.TcpServerChannel(8080);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(t, "customer", WellKnownObjectMode.Singleton);
//RemotingConfiguration.ApplicationName = "remoteserver";//RemotingConfiguration.RegisterActivatedServiceType(t);
Console.WriteLine("Press enter to exit.");
Console.Read();
}
}
}
Client
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Interfaces;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Channels;
namespaceClient
{
classProgram
{
staticvoidMain(string[] args)
{
System.Runtime.Remoting.Channels.Tcp.TcpClientChannel channel = new System.Runtime.Remoting.Channels.Tcp.TcpClientChannel();
ChannelServices.RegisterChannel(channel, false);
ICustomer cust = (ICustomer)Activator.GetObject(typeof(ICustomer), "tcp://localhost:8080/customer");
//ICustomer cust = (ICustomer)Activator.CreateInstance(typeof(ICustomer), null, new object[] {new UrlAttribute("tcp://localhost:8080")} );
RemotingConfiguration.RegisterActivatedClientType(typeof(ICustomer), "tcp://localhost:8080/remoteserver");
//ICustomer cust = n
Console.WriteLine("Name: " + cust.getName());
Console.Read();
}
}
}
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Trinity105 reputationPosted Oct 11, 2009, 7:15 AM EDT
0
Then you have to implement your logic confoming to proxy pattern
you create an assembly within witch you create an interface that define the contract and a proxy class inherits from the interface
create an assembly that contains implementation this last one must implements the interface
add a reference to the assembly that contains the implementation from the assembly that contains the interface and the interface
define a new instance of the class or classes that or those contain implementation within the proxy
then expose only the assembly that contains the interface and the proxy to the server
Trinity105 reputationPosted Oct 11, 2009, 7:15 AM EDT
you create an assembly within witch you create an interface that define the contract and a proxy class inherits from the interface
create an assembly that contains implementation this last one must implements the interface
add a reference to the assembly that contains the implementation from the assembly that contains the interface and the interface
define a new instance of the class or classes that or those contain implementation within the proxy
then expose only the assembly that contains the interface and the proxy to the server
Harris4 reputationPosted Oct 11, 2009, 2:29 PM EDT