Abstract factory and remoting

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Max (mi97ki_at_yahoo.com)
Date: 05/22/04

  • Next message: stephan wellmann via .NET 247: "MBR on Server is not garbage collected"
    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).


  • Next message: stephan wellmann via .NET 247: "MBR on Server is not garbage collected"

    Relevant Pages

    • Re: Abstract factory and remoting
      ... made the Factory local to the Client. ... AbsServer - ... Factory - not remotable anymore, invokes the remotable Servers ...
      (microsoft.public.dotnet.framework.remoting)
    • Re: Abstract factory and remoting
      ... The Servers are remotable objects hosted in IIS. ... Client ... >Cannot load type myNamespace.Factory, Factory. ... >typeName, String assemblyName) ...
      (microsoft.public.dotnet.framework.remoting)
    • Re: [fw-wiz] Defense in Depth to the Desktop
      ... > network hardware mechanisms. ... The Strong Internal Network Defense ... The client subnet and the server ... Servers are allowed to reply to clients, ...
      (Firewall-Wizards)
    • [fw-wiz] Defense in Depth to the Desktop
      ... network hardware mechanisms. ... controls is highlighted when the internal network and systems suffer ... The client subnet and the server ... Servers are allowed to reply to clients, ...
      (Firewall-Wizards)
    • Re: [fw-wiz] Defense in Depth to the Desktop
      ... Sounds a lot like Domain Based Security (not Windows 'domains', ... > network hardware mechanisms. ... The client subnet and the ... Servers are allowed to reply to clients, ...
      (Firewall-Wizards)