2009-10-07 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Wed, 7 Oct 2009 09:47:43 +0000 (09:47 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Wed, 7 Oct 2009 09:47:43 +0000 (09:47 -0000)
* ServiceHostBase.cs : a couple of refactoring on contract loopup.
  Do not push mex contracts to ImplementedContracts.

svn path=/trunk/mcs/; revision=143609

mcs/class/System.ServiceModel/System.ServiceModel/ChangeLog
mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs

index 9547f5ba81e0dea1b65d2e426f61df4b6240d34e..4c04d7d09898b10b7b8ee808348fb1c605e318c1 100755 (executable)
@@ -1,3 +1,8 @@
+2009-10-07  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * ServiceHostBase.cs : a couple of refactoring on contract loopup.
+         Do not push mex contracts to ImplementedContracts.
+
 2009-10-02  Atsushi Enomoto  <atsushi@ximian.com>
 
        * ServiceHostingEnvironment.cs : revert the change, to use
index 3d21380b7bd2ec28cc8f100909c61d22af2a85de..3e448118a9e927f61368b21444e10d6c4de5db92 100644 (file)
@@ -205,43 +205,46 @@ namespace System.ServiceModel
                        return null;
                }
 
+               ContractDescription mex_contract, help_page_contract;
+
                ContractDescription GetContract (string name)
                {
-                       //FIXME: hack hack hack
-                       ImplementedContracts ["IHttpGetHelpPageAndMetadataContract"] =
-                               ContractDescription.GetContract (typeof (IHttpGetHelpPageAndMetadataContract));
-
-                       // FIXME: As long as I tried, *only* IMetadataExchange
-                       // is the exception case that does not require full
-                       // type name. Hence I treat it as a special case.
-                       if (name == ServiceMetadataBehavior.MexContractName) {
-                               if (!Description.Behaviors.Contains (typeof (ServiceMetadataBehavior)) && Array.IndexOf (Description.ServiceType.GetInterfaces (), typeof (IMetadataExchange)) < 0)
-                                       throw new InvalidOperationException (
-                                               "Add ServiceMetadataBehavior to the ServiceHost to add a endpoint for IMetadataExchange contract.");
-                                       
-                               ImplementedContracts [ServiceMetadataBehavior.MexContractName] =
-                                       ContractDescription.GetContract (typeof (IMetadataExchange));
-
-                               foreach (ContractDescription cd in ImplementedContracts.Values)
-                                       if (cd.ContractType == typeof (IMetadataExchange))
-                                               return cd;
-                               return null;
+                       // FIXME: not sure if they should really be special cases.
+                       switch (name) {
+                       case "IHttpGetHelpPageAndMetadataContract":
+                               if (help_page_contract == null)
+                                       help_page_contract = ContractDescription.GetContract (typeof (IHttpGetHelpPageAndMetadataContract));
+                               return help_page_contract;
+                       case "IMetadataExchange":
+                               // this is certainly looking special (or we may 
+                               // be missing something around ServiceMetadataExtension)
+                               if (Extensions.Find<ServiceMetadataExtension> () == null)
+                                       break;
+                               if (mex_contract == null)
+                                       mex_contract = ContractDescription.GetContract (typeof (IMetadataExchange));
+                               return mex_contract;
                        }
 
+                       // FIXME: probably type-to-contract-name mapping is wrong. 
+                       // This "loopup by type name" incorrectly allows
+                       // "System.ServiceModel.Description.IMetadataExchange",
+                       // but disabling this results in couple of regressions.
+                       // So I keep enabling it so far. But it smells wrong.
                        Type type = PopulateType (name);
 
                        foreach (ContractDescription cd in ImplementedContracts.Values) {
-                               // FIXME: This check is a negative side effect 
-                               // of the above hack.
-                               if (cd.ContractType == typeof (IMetadataExchange))
-                                       continue;
-
                                if (type == null) {
                                        if (cd.Name == name)
                                                return cd;
                                        continue;
                                }
 
+                               // FIXME: This check is a negative side effect 
+                               // of the above hack. (but it should not still 
+                               // skip name-based match). Seealso above FIXMEs.
+                               if (cd.ContractType == typeof (IMetadataExchange))
+                                       continue;
+
                                if (cd.ContractType == type ||
                                    cd.ContractType.IsSubclassOf (type) ||
                                    type.IsInterface && cd.ContractType.GetInterface (type.FullName) == type)
@@ -347,14 +350,6 @@ namespace System.ServiceModel
                        return ConfigUtil.ServicesSection.Services [serviceType.FullName];                      
                }
 
-               internal ContractDescription GetContract (string name, string ns)
-               {
-                       foreach (ContractDescription d in ImplementedContracts.Values)
-                               if (d.Name == name && d.Namespace == ns)
-                                       return d;
-                       return null;
-               }
-
                protected abstract ServiceDescription CreateDescription (
                        out IDictionary<string,ContractDescription> implementedContracts);