Merge pull request #2374 from lambdageek/dev/bug-37035
authorAleksey Kliger (λgeek) <akliger@gmail.com>
Tue, 22 Dec 2015 12:33:03 +0000 (07:33 -0500)
committerAleksey Kliger (λgeek) <akliger@gmail.com>
Tue, 22 Dec 2015 12:33:03 +0000 (07:33 -0500)
[WCF] ServiceHost should look for inherited ServiceBehaviorAttribute

mcs/class/System.ServiceModel/System.ServiceModel/ServiceHost.cs
mcs/class/System.ServiceModel/Test/System.ServiceModel/ServiceHostTest.cs

index 2fed9fb3cdb9ff644e3bc27dddc450c3aa99d8a0..e438c8f5b71f59e09ced2747c4c82441254084b4 100644 (file)
@@ -151,7 +151,7 @@ namespace System.ServiceModel
 
                TAttr PopulateAttribute<TAttr> ()
                {
-                       object [] atts = service_type.GetCustomAttributes (typeof (TAttr), false);
+                       object [] atts = service_type.GetCustomAttributes (typeof (TAttr), true);
                        return (TAttr) (atts.Length > 0 ? atts [0] : Activator.CreateInstance (typeof (TAttr)));
                }
 
index a120402ff7cc6bbcdcaadc235ad311843ca49752..c93c7953d4915f1205ea91770faee6abb67a0342 100644 (file)
@@ -353,6 +353,29 @@ namespace MonoTests.System.ServiceModel
                        }
                }
 
+               [Test]
+               public void InstanceWithSingletonMode_InheritServiceBehavior ()
+               {
+                       // # 37035
+
+                       var ep = NetworkHelpers.LocalEphemeralEndPoint ().ToString ();
+
+                       ChildSingletonService instance = new ChildSingletonService ();
+                       ServiceHost host = new ServiceHost (instance);
+
+                       host.AddServiceEndpoint (typeof (SingletonService),
+                                                new BasicHttpBinding (),
+                                                new Uri ("http://" + ep + "/s3"));
+
+                       try {
+                               host.Open ();
+                       } catch (InvalidOperationException ex) {
+                               Assert.Fail ("InstanceContextMode was not inherited from parent, exception was: {0}", ex);
+                       } finally {
+                               host.Close ();
+                       }
+               }
+
                [ServiceContract]
                interface IBar
                {
@@ -446,7 +469,14 @@ namespace MonoTests.System.ServiceModel
                public class SingletonService
                {
                        [OperationContract]
-                       public void Process (string input)
+                       public virtual void Process (string input)
+                       {
+                       }
+               }
+
+               public class ChildSingletonService : SingletonService
+               {
+                       public override void Process (string input)
                        {
                        }
                }