Re: Abstract factory and remoting

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

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

  • Next message: Sutty: "The remote server returned an error: (405) Method Not Allowed."
    Date: 22 May 2004 17:16:52 -0700
    
    

    To simplify things a little, I eliminated AbsFactory. In addition, I
    made the Factory local to the Client. So now my app consists of:

    1. AbsServer - (no changes)
    2. Server - (no changes)
    3. Factory - not remotable anymore, invokes the remotable Servers
            public class Factory
            {
               public Factory()
               {
                  RemotingConfiguration.Configure(
                          
    "C:\\VCNETProjects\\MyObj2\\Factory\\factory.config");
                    }

                    public AbsServer CreateServer(string type)
                    {
                       string url = "http://MAMBO/myIISObj/Server.soap";
                       AbsServer obj = null;
                       if(type == "Leapfrog")
                       {
                          obj = (AbsServer)Activator.GetObject(
                                          typeof(myNamespace.Leapfrog), url );
                       }
                          else if(type == "Hermite")
                       {
                          obj = (AbsServer)Activator.GetObject(
                                          typeof(myNamespace.Hermite), url );
                       }
                       else
                       {
                          Console.WriteLine("Unrecognized type");
                       }

                       return obj;
                    } // CreateServer
               } // class Factory

    5. Client - modified
            class Cient
            {
               [STAThread]
               static void Main(string[] args)
               {
                      Factory f = new Factory();

                      AbsServer server = f.CreateServer("Leapfrog");

                      server.SetData(3);

                      Console.WriteLine(server.GetData());
               } // Main
            } // class Client

    The Factory configuration file is:
    <configuration>
      <system.runtime.remoting>
        <application name="Factory">
          <client url="http://MAMBO/myIISObj">
            <wellknown type="myNamespace.Leapfrog, Server"
                        url="http://MAMBO/myIISObj/Server.soap"/>
          </client>
          <channels>
            <channel ref="http" />
          </channels>
        </application>
      </system.runtime.remoting>
    </configuration>

    Now the runtime thows an exception when the statement:
            server.SetData(3);
    is invoked.

    The trace is:
    An unhandled exception of type
    'System.Runtime.Remoting.RemotingException' occurred in mscorlib.dll

    Additional information: System.Runtime.Remoting.RemotingException:
    Cannot load type myNamespace.Leapfrog, Server.
       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)

    Anybody out there???

    mi97ki@yahoo.com (Max) wrote in message news:<7bdb212b.0405220922.7d962c60@posting.google.com>...
    > 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: Sutty: "The remote server returned an error: (405) Method Not Allowed."

    Relevant Pages

    • Abstract factory and remoting
      ... The Servers are remotable objects hosted in IIS. ... Factory (concrete remotable Factory - contains references to ... Client ... configuration file is: ...
      (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)