Abstract factory and remoting
From: Max (mi97ki_at_yahoo.com)
Date: 05/22/04
- Previous message: MoeJoe: "Client/Server"
- Next in thread: Max: "Re: Abstract factory and remoting"
- Reply: Max: "Re: Abstract factory and remoting"
- Reply: Allen Anderson: "Re: Abstract factory and remoting"
- Messages sorted by: [ date ] [ thread ]
Date: 22 May 2004 10:22:04 -0700
Hi,
I developed an application that allows a client to build objects
(called Servers, for simplicity) of a specific type using an abstract
factory. The Servers are remotable objects hosted in IIS. This are the
various modules the application consists of:
1. AbsServer (interface to the concrete Servers)
public interface AbsServer
{
int GetData();
void SetData(int a_n);
} // class AbsServer
2. AbsFactory (interface to the concrete Factories - contains a
reference to AbsServer)
public interface AbsFactory
{
AbsServer CreateServer(string type);
} // class IntegratorAbsFactory
3. Server (concrete remotable object - contains a reference to
AbsServer)
public class Leapfrog : MarshalByRefObject, AbsServer
{
public Leapfrog()
{
Console.WriteLine("I am a Leapfrog!");
}
public int GetData()
{
return 3*m_n;
}
public void SetData(int a_n)
{
m_n = a_n;
}
private int m_n;
} // class Leapfrog
public class Hermite : MarshalByRefObject, AbsServer
{
public Hermite()
{
Console.WriteLine("I am a Hermite!");
}
public int GetData()
{
return 2*m_n;
}
public void SetData(int a_n)
{
m_n = a_n;
}
private int m_n;
} // class Hermite
}
4. Factory (concrete remotable Factory - contains references to
AbsFactory, AbsServer and Server)
public class Factory : MarshalByRefObject, AbsFactory
{
public AbsServer CreateServer(string type)
{
AbsServer obj = null;
if(type == "Leapfrog")
{
obj = new Leapfrog();
}
else if(type == "Hermite")
{
obj = new Hermite();
}
else
{
Console.WriteLine("Unrecognized type");
}
return obj;
} // CreateServer
} // class Factory
5. Client (contains references to AbsFactory and AbsServer)
class Client
{
[STAThread]
static void Main(string[] args)
{
//Load the Http Channel from the config file
try
{
RemotingConfiguration.Configure(
"C:\\VCNETProjects\\MyObj\\Client\\ClientFactory.config");
}
catch
{
Console.WriteLine("Exception!");
}
//instantiate the remote object on the server
//(this is really just a proxy object here)
string url = "http://MAMBO/myIISObj/Factory.soap";
myNamespace.AbsFactory af =
(myNamespace.AbsFactory)Activator.GetObject(
typeof(myNamespace.AbsFactory), url );
myNamespace.AbsServer leapfrog = af.CreateServer("Leapfrog");
leapfrog.SetData(3);
Console.WriteLine(leapfrog.GetData());
}
}
All the modules (with the exception of the Client) live in the same
namespace (myNamespace) and for now are deployed on the same computer.
Factories and Servers are the remotable objects hosted in IIS (virtual
directory myIISObj.
Factories are Server Activated Objects and the associated
configuration file is:
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="Singleton" type="myNamespace.Factory,
Factory"
objectUri="Factory.soap" />
</service>
</application>
</system.runtime.remoting>
</configuration>
The Servers are Client Activated Objects and they should not need a
configuration file.
The Client configuration file is:
<configuration>
<system.runtime.remoting>
<application name="Client">
<client url="http://MAMBO/myIISObj">
<wellknown type="myNamespace.Factory, Factory"
url="http://MAMBO/myIISObj/Factory.soap"/>
</client>
<channels>
<channel ref="http" />
</channels>
</application>
</system.runtime.remoting>
</configuration>
When I run the client, the .NET runtime throws an exception at the
statement:
myNamespace.AbsServer leapfrog = af.CreateServer("Leapfrog");
An unhandled exception of type
'System.Runtime.Remoting.RemotingException' occurred in mscorlib.dll
Additional information: System.Runtime.Remoting.RemotingException:
Cannot load type myNamespace.Factory, Factory.
at System.Runtime.Remoting.RemotingConfigInfo.LoadType(String
typeName, String assemblyName)
at System.Runtime.Remoting.RemotingConfigInfo.GetServerTypeForUri(String
URI)
at System.Runtime.Remoting.RemotingConfigHandler.GetServerTypeForUri(String
URI)
at System.Runtime.Remoting.RemotingServices.GetServerTypeForUri(String
URI)
at System.Runtime.Remoting.Channels.Http.HttpRemotingHandler.CanServiceRequest(HttpContext
context)
at System.Runtime.Remoting.Channels.Http.HttpRemotingHandler.InternalProcessRequest(HttpContext
context)
What am I doing wrong? Why the runtime cannot load the Factory
assembly (I verified that IIS is running and that both Factory.dll and
Server.dll are stored in the virtual directory).
- Previous message: MoeJoe: "Client/Server"
- Next in thread: Max: "Re: Abstract factory and remoting"
- Reply: Max: "Re: Abstract factory and remoting"
- Reply: Allen Anderson: "Re: Abstract factory and remoting"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|