Mike, Thanks for the effort, unfortunately my manager isn't going to buy this. I may have to rethink the architecture. I'll get back to this list when I come up with something. Thanks again though for your suggestion. John
-----Original Message----- From: Mike Woodring (DevelopMentor) [mailto:woodring@;DEVELOP.COM] Sent: Friday, November 08, 2002 4:03 PM To: [EMAIL PROTECTED] Subject: Re: [ADVANCED-DOTNET] Getting the Real Object registered on the Remoting server so that I could get to its ObjRef The best I can come up with relies on reflection against non-public types in System.Runtime.Remoting. It works, but due to the nature of the code isn't guaranteed to continue working on future builds of the runtime :-) I've encapsulated the code (below) in a RemotingIdentity helper that supports a usage model like this: ObjRef orFoo; if( RemotingIdentity.GetObjRefForUri("fooUri", out orFoo2) ) { // URI found in identity table, orFoo is not initialized } else { // No object found with that URI. } Use at your own risk :-) public class RemotingIdentity { // GetObjRefForUri // Looks up the specified uri in the remoting runtime's identity // mapping table and, if found, returns true along with the // associated ObjRef. Returns false if the URI cannot be mapped // to anything. // public static bool GetObjRefForUri( string objUri, out ObjRef objRef ) { // The following code is the reflection-based equivalent of: // // Identity idObj = IdentityHolder.ResolveIdentity(objUri); // return(idObj.ObjectRef); // object idObj = IdentityHolder_ResolveIdentity.Invoke(null, new object[]{objUri}); if( idObj != null ) { objRef = (ObjRef)Identity_GetObjRef.GetValue(idObj, null); } else { objRef = new ObjRef(); } return(idObj != null); } private static MethodInfo IdentityHolder_ResolveIdentity; private static PropertyInfo Identity_GetObjRef; static RemotingIdentity() { // This class makes use of reflection against private types // in System.Runtime.Remoting. So this static constructor // does two things: (1) looks up and caches the necessary // member info once and (2) throws exceptions if the types and // members being saught after cannot be located. // Assembly a = Assembly.LoadWithPartialName("mscorlib"); Type t = a.GetType("System.Runtime.Remoting.IdentityHolder"); if( t == null ) throw new ApplicationException("Failed to locate IdentityHolder type"); IdentityHolder_ResolveIdentity = t.GetMethod("ResolveIdentity", BindingFlags.Static | BindingFlags.NonPublic); if( IdentityHolder_ResolveIdentity == null ) throw new ApplicationException("Failed to locate IdentityHolder.ResolveIdentity"); t = a.GetType("System.Runtime.Remoting.Identity"); Identity_GetObjRef = t.GetProperty("ObjectRef", BindingFlags.Instance | BindingFlags.NonPublic); if( Identity_GetObjRef == null ) throw new ApplicationException("Failed to locate Identity.ObjectRef property"); } } -Mike DevelopMentor http://staff.develop.com/woodring http://www.develop.com/devresources ----- Original Message ----- From: "Abdulla, Jehangir" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, November 08, 2002 10:20 AM Subject: Re: [ADVANCED-DOTNET] Getting the Real Object registered on the Remoting server so that I could get to its ObjRef Still trying to figure out how to get around this issue, any ideas anyone ? -----Original Message----- From: Abdulla, Jehangir Sent: Thursday, November 07, 2002 4:42 PM To: [EMAIL PROTECTED] Subject: [ADVANCED-DOTNET] Getting the Real Object registered on the Remoting server so that I could get to its ObjRef Don't know if this is a pretty simple question but I have spent a couple of hours in trying to figure this out I have a method on the server side that returns the ObjRef of a Singleton. This method checks if the Singleton is registered already with the Remoting Infrastructure, if it is, it returns the ObjRef, if not it creates the object, registers it with the remoting infrastructure and returns the ObjRef. The latter part i.e. creating the object and returning the ObjRef is pretty simple, what I'm struggling with is returning the ObjRef if the object is already registered as a singleton. Here's what I have done so far. public ObjRef GetRemoteObject(string friendlyName) { string assemblyName = String.Empty; string className = String.Empty; // look up the type name and the assembly name in the // database based on the friendly name passed in // see if object is registered, if it is return object WellKnownServiceTypeEntry[] wstes = RemotingConfiguration.GetRegisteredWellKnownServiceTypes(); foreach(WellKnownServiceTypeEntry wste in wstes) { if(wste.ObjectType.FullName == className + ", " + assemblyName) // here I need to return the ObjRef of the object if it is already registered // any ideas on how I could do that ? return a new ObjRef that points to the same object or return the same ObjRef // Any ideas on how to get the ObjRef of the existing object thats registered. // If somehow I could get access to the Real Object itself from the // WellKnownServiceTypeEntry, I could use something like this to get a new // ObjRef // ObjRef newObjRef = new ObjRef(howdoIGetAccessToTheObject, wste.ObjectType); // return newObjRef; } MarshalByRefObject obj = (MarshalByRefObject)Activator.CreateInstance (assemblyName,typeName).Unwrap(); // TODO: register this obj with the remoting framework here as a singleton return RemotingServices.Marshal(obj,objectUri); } TIA, John You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.
