2004-04-14 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / corlib / System.Runtime.Remoting / RemotingServices.cs
index 5c4b365ce9e6d5c9ba5adb1dfbe6142a7416e8a3..09f649274a0636be6c138edf3a968b792c24fd31 100644 (file)
@@ -129,7 +129,7 @@ namespace System.Runtime.Remoting
                                if (proxy.GetProxiedType().IsContextful && (proxy.ObjectIdentity is ServerIdentity))
                                        identity = proxy.ObjectIdentity as ServerIdentity;
                                else
-                                       throw new ArgumentException ("The obj parameter is a proxy");
+                                       throw new ArgumentException ("The obj parameter is a proxy.");
                        }
                        else
                                identity = obj.ObjectIdentity;
@@ -146,7 +146,7 @@ namespace System.Runtime.Remoting
 
                public static Type GetServerTypeForUri (string uri)
                {
-                       Identity ident = GetIdentityForUri (uri);
+                       ServerIdentity ident = GetIdentityForUri (uri) as ServerIdentity;
                        if (ident == null) return null;
                        return ident.ObjectType;
                }
@@ -203,7 +203,7 @@ namespace System.Runtime.Remoting
 
                                if (identity != null)
                                {
-                                       if (identity.ObjectType.IsContextful && !identity.IsConnected)
+                                       if (proxy.GetProxiedType().IsContextful && !identity.IsConnected)
                                        {
                                                // Unregistered local contextbound object. Register now.
                                                ClientActivatedIdentity cboundIdentity = (ClientActivatedIdentity)identity;
@@ -214,12 +214,10 @@ namespace System.Runtime.Remoting
                                                return cboundIdentity.CreateObjRef(requested_type);
                                        }
                                        else if (uri != null)
-                                               throw new RemotingException ("It is not possible marshal a proxy of a remote object");
+                                               throw new RemotingException ("It is not possible marshal a proxy of a remote object.");
 
                                        return proxy.ObjectIdentity.CreateObjRef(requested_type);
                                }
-                               else
-                                       throw new NotSupportedException ();     // TODO
                        }
 
                        if (requested_type == null) requested_type = obj.GetType();
@@ -239,7 +237,10 @@ namespace System.Runtime.Remoting
                                        CreateClientActivatedServerIdentity (obj, requested_type, uri);
                        }
 
-                       return obj.CreateObjRef(requested_type);
+                       if (IsTransparentProxy (obj))
+                               return RemotingServices.GetRealProxy(obj).ObjectIdentity.CreateObjRef (requested_type);
+                       else
+                               return obj.CreateObjRef(requested_type);
                }
 
                static string NewUri ()
@@ -250,7 +251,7 @@ namespace System.Runtime.Remoting
 
                public static RealProxy GetRealProxy (object proxy)
                {
-                       if (!IsTransparentProxy(proxy)) throw new RemotingException("Cannot get the real proxy from an object that is not a transparent proxy");
+                       if (!IsTransparentProxy(proxy)) throw new RemotingException("Cannot get the real proxy from an object that is not a transparent proxy.");
                        return (RealProxy)((TransparentProxy)proxy)._rp;
                }
 
@@ -258,7 +259,7 @@ namespace System.Runtime.Remoting
                {
                        Type type = Type.GetType (msg.TypeName);
                        if (type == null)
-                               throw new RemotingException ("Type '" + msg.TypeName + "' not found!");
+                               throw new RemotingException ("Type '" + msg.TypeName + "' not found.");
 
                        BindingFlags bflags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
                        if (msg.MethodSignature == null)
@@ -293,7 +294,7 @@ namespace System.Runtime.Remoting
                        if (IsTransparentProxy(obj))
                                return ((ClientIdentity)GetRealProxy (obj).ObjectIdentity).EnvoySink;
                        else
-                               throw new ArgumentException ("obj must be a proxy","obj");                      
+                               throw new ArgumentException ("obj must be a proxy.","obj");                     
                }
 
                public static void LogRemotingStage (int stage)
@@ -301,10 +302,10 @@ namespace System.Runtime.Remoting
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public static string GetSessionIdForMethodMessage(IMethodMessage msg)
                {
-                       throw new NotImplementedException (); 
+                       // It seems that this it what MS returns.
+                       return msg.Uri;
                }
 
                public static bool IsMethodOverloaded(IMethodMessage msg)
@@ -338,7 +339,7 @@ namespace System.Runtime.Remoting
                        return atts.Length > 0;
                }
 
-               public static bool IsAsyncMessage(IMessage msg)
+               internal static bool IsAsyncMessage(IMessage msg)
                {
                        if (! (msg is MonoMethodMessage)) return false;
                        else if (((MonoMethodMessage)msg).IsAsync) return true;
@@ -518,7 +519,7 @@ namespace System.Runtime.Remoting
                        lock (uri_hash)
                        {
                                if (uri_hash.ContainsKey (identity.ObjectUri)) 
-                                       throw new RemotingException ("Uri already in use: " + identity.ObjectUri);
+                                       throw new RemotingException ("Uri already in use: " + identity.ObjectUri + ".");
 
                                uri_hash[identity.ObjectUri] = identity;
                        }
@@ -568,7 +569,12 @@ namespace System.Runtime.Remoting
                        lock (uri_hash)
                        {
                                if (!ident.Disposed) {
-                                       uri_hash.Remove (ident.ObjectUri);
+                                       ClientIdentity clientId = ident as ClientIdentity;
+                                       if (clientId != null)
+                                               uri_hash.Remove (GetNormalizedUri (clientId.TargetUri));
+                                       else
+                                               uri_hash.Remove (ident.ObjectUri);
+                                               
                                        ident.Disposed = true;
                                }
                        }