Microsoft Office Automation and .NET Remoting

P

Probashi

Hi,

I have .net object that runs a Microsoft Access application and I want
to expose this object through remoting. Here is my sample code:

Server Object :

public class Server : MarshalByRefObject
{
private Access.Application aa;

public void execute()
{
aa = new Access.Application();
aa.OpenCurrentDatabase (@"C:\tmp\tmp.mdb",false);
//do something else
}

Access.dll is the CRW for Access.Application (MS Access OLE Automation
object)

Client:

public class Client
{
public static int Main(string [] args)
{
Server obj = (Server)
Activator.GetObject(
typeof(Server),
"tcp://localhost:8086/ServerURI");
if (obj == null)
System.Console.WriteLine("Could not locate server");
else
{
obj.execute();
}
return 0;
}
}
}

I got File or Assembly not found exception, it is looking for my
Access.dll, which is only installed on the server and I do not want to
install this on the client. How can I solve this problem.

Thanks
 
C

cedricb

If you dont want the implementation code on the client, you need to access
the remote object through an interface. Place the interface in a seperate
DLL. Make the client AND server reference this interface. The server must
implement the interface. I am not very good at C# but here is my stab at
the C# code. All of the code is in the same module in my example, but
should be broken out into different assemblies for your product. You need
to place the assembly with the interface definition on the client AND the
server. Here is the code:

public interface RemotingInterface

{

void execute();

}

public class Server:MarshalByRefObject, RemotingInterface

{

public void execute()

{

//put execute code here

}

}

public class Client

{

Object obj;

RemotingInterface myRemoteObj;

public Client()

{

obj = Activator.GetObject(typeof(RemotingInterface),
"tcp://localhost:8086/ServerURI");

myRemoteObj = (RemotingConfiguration)obj;

myRemoteObj.execute();

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top