Ejemplo n.º 1
0
 /// <summary>
 /// creates an IOR for an object hosted in the local appdomain.
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 internal static Ior CreateIorForObjectFromThisDomain(MarshalByRefObject obj, Type forType, bool marshalUsingForType) {
     Console.WriteLine("Marshalling using for type: {0}", marshalUsingForType);
     ObjRef objRef = 
         marshalUsingForType ? RemotingServices.Marshal(obj, null, forType)
                             : RemotingServices.Marshal(obj); // make sure, the object is marshalled and get obj-ref
     byte[] objectKey = GetObjectKeyForUri(objRef.URI);
     IiopChannelData serverData = GetIiopChannelData(objRef);
     if (serverData != null) {
         string host = serverData.HostName;
         int port = serverData.Port;
         if ((objectKey == null) || (host == null)) {
             // the objRef: " + refToTarget + ", uri: " +
             // refToTarget.URI + is not serialisable, because connection data is missing
             // hostName=host, objectKey=objectKey
             throw new INV_OBJREF(1961, CompletionStatus.Completed_MayBe);
         }
         string repositoryID = forType == ReflectionHelper.MarshalByRefObjectType
             ? "" // CORBA::Object has "" repository id
             : Repository.GetRepositoryID(forType);
         // this server support GIOP 1.2 --> create an GIOP 1.2 profile
         InternetIiopProfile profile = new InternetIiopProfile(new GiopVersion(1, 2), host,
                                                               (ushort)port, objectKey);
         // add additional tagged components according to the channel options, e.g. for SSL
         profile.AddTaggedComponents(serverData.AdditionalTaggedComponents);
         // add additional tagged components according to registered interceptors:
         AddProfileComponentsFromIorInterceptors(profile);
         
         Ior ior = new Ior(repositoryID, new IorProfile[] { profile });
         return ior;
     } else {
         Debug.WriteLine("ERROR: no server-channel information found!");
         Debug.WriteLine("Please make sure, that an IIOPChannel has been created with specifying a listen port number (0 for automatic)!");
         Debug.WriteLine("e.g. IIOPChannel chan = new IIOPChannel(0);");
         throw new INTERNAL(1960, CompletionStatus.Completed_MayBe);
     }
 }