If you are a Microsoft developer, already comfortable with .NET Remoting, or new to distributed technologies, start with “A simple .NET Remoting example”. Developers familiar with J2EE should start with “A simple J2EE example”, and those familiar with CORBA should start with “A simple CORBA example”.The following three lines of code show how easily you can instantiate the remote object MyServer and call a Method() on it.The information for establishing a connection with the server and locating the remote object are contained in an XML configuration file, as shown in “.NET Remoting configuration”.There is no concept of narrowing an object’s type in .NET. You locate the object and cast it to its specific type all in one step.The next line creates an instance of myServer.It’s that simple! If you want more information on configuring .NET Remoting using the VisiBroker for .NET protocol, see “.NET Remoting configuration”.The next two lines declare a variable to contain the location of the EJBHome object (myServerHomeObject) on the server, and look it up.The next line creates an instance of myServer.Finally we can invoke a method on MyServer:The next two lines declare a variable to contain the location of the factory object (myServerHomeObject) on the server, and look it up.The next line creates an instance of myServer.Finally we can invoke a method on MyServer.This section contains the details of the configuration file alluded to in the .NET example in “A simple .NET Remoting example”.When we instantiated MyServerHome in the first line of the example, we used the new operator on MyServerHomeRemotingProxy(). In order to locate the object on which to make the call, the example configuration file uses the wellknown element,<wellknown type="MyServerHomeRemotingProxy, MyApplication"where MyServerHomeRemotingProxy is the type name and MyApplication is the name of the assembly where the type is defined.MyServerHome is represented as a wellknown object (also known as Server-activated object or SAO). Any CORBA or EJB server object can be represented as an SAO. In addition, EJBs can be represented as Client Activated Objects (CAO). See “Client-activated objects vs. server-activated objects” for more information.
• The janeva: protocol prefix tells the application to use the IIOP channel (Janeva.Remoting.IiopChannel), specified in the <channel> element of the configuration file.
• corbaname:rir:#location/of/my/server/object is one of several CORBA ORB string_to_object() compatible URL schemes. See the table in “URL schemes” for more examples and descriptions of the URL schemes.
The corbaname URL scheme is most often used to resolve EJBs. It allows URLs to denote entries in a Naming Service. The host address is the location and listening port of the Naming Service and it can be formatted as <NS_host_name>:<NS_port> or <NS_ip_address>:<NS_port>. More details about the corbaname URL scheme are available in the OMG CORBA specification. The corbaloc URL scheme provides direct access to server objects by location and object key. It is not often used because of the limited amount of addressing power. More details about the corbaloc URL scheme are available in the OMG CORBA specification. The osagent scheme is a private feature for using with VisiBroker CORBA server objects.To avoid ambiguity, all colons (:) in the <interface_repository_id> must be prefixed with the backslash (\) character, as follows: janeva:osagent:repid:IDL\:com/semagroup/targys/servicelayer/corba/ServiceRootI\:1.0:SL_demo_server The IOR URL scheme allows you to look up an object by stringified object reference (IOR). To communicate with remote objects a .NET client application has to create and register a Remoting channel. The channel provides a conduit for communication between a client and a remote object.Instead of using the .NET Framework Channels types, VisiBroker for .NET provides the Janeva.Remoting.IiopChannel type for creating a channel on IIOP.
• Server activation. Server-activated objects (SAO) are created by the server only when they are needed. They are not created when the client proxy is created by calling new or Activator.GetObject, but rather when the client invokes the first method on that proxy. The previous sections in this chapter are examples of this object activation method.
• Client activation. Use client-activated objects when the application needs to retain state between method calls and also needs to pair each client with a unique object instance. Client-activated objects (CAO) are created on the server when the client calls new or Activator.CreateInstance.For example, let’s consider a simple EJB interface, SimpleSession, and its home interface, SimpleSessionHome:The SimpleSession interface configured as an SAO can be accessed on the client side in C# as follows:If the SimpleSession interface is represented as a CAO, the client code is a bit simpler:First, the java2cs compiler has extended knowledge of the EJB home interface. The compiler maps some methods defined on the EJB home interface to constructors of the bean’s Remoting Proxy class in the generated C# code. For the Session EJB home (stateful or stateless), these are any create() methods. For the Entity EJB home, this is the findByPrimaryKey() method. Also, the java2cs compiler preserves the parameters of the original home method in the generated proxy constructor. For example, the SimpleSessionHome.create(String name) method maps to the SimpleSessionRemotingProxy(string name) constructor in the generated C# code.When a new instance of the CAO Remoting Proxy is created, the VisiBroker for .NET runtime does a few things under the covers. First, it resolves the bean’s home interface based on the VisiBroker for .NET URL specified in the Remoting object configuration. Then, depending on whether this is a Session bean or an Entity bean, the runtime remotely calls either the corresponding Session’s create() method, or the Entity’s findByPrimaryKey() method. Lastly, the Remoting Proxy of the EJB instance, resulted by this call, becomes an object returned by the new statement.
1 Creating an EJB Remoting Proxy, configured as a CAO, does not always imply that a new EJB instance is created on the server side (the EJB container). While this is true for the Session beans, the Entity beans behave differently. For Entities, the CAO constructor call translates into the findByPrimaryKey() call, therefore an existing instance with the corresponding primary key must already exist, otherwise an exception will be thrown. Thus, the CAO representation of the Entity bean can be used only to resolve a bean instance, not to create one. To create a new Entity instance use the SAO model.
2 VisiBroker for .NET Client-activated objects do not support the lifetime lease model. This is due to the fact that the EJB models this concept. Moreover, the EJB life cycle is different depending on the EJB type. The client-side developer needs to understand these differences and explicitly call the Remove() method on the EJB interface or the home when the EJB instance is no longer needed.The third line declares a variable to contain the location of the factory object (myServerHomeObject) on the server, and look it up similar to the way it was done in the J2EE and CORBA examples in the previous sections, except that there is no narrowing in .NET.