Browse Source

2009-07-02 Atsushi Enomoto <[email protected]>

	* ContractDescriptionGenerator.cs : do not reject derived service
	  contract from another service contract type.

	* ContractDescriptionTest.cs : added test for derived contract type.


svn path=/trunk/mcs/; revision=137288
Atsushi Eno 16 years ago
parent
commit
2b471a3555

+ 5 - 0
mcs/class/System.ServiceModel/System.ServiceModel.Description/ChangeLog

@@ -1,3 +1,8 @@
+2009-07-02  Atsushi Enomoto  <[email protected]>
+
+	* ContractDescriptionGenerator.cs : do not reject derived service
+	  contract from another service contract type.
+
 2009-06-10  Atsushi Enomoto  <[email protected]>
 
 	* ServiceThrottlingBehavior.cs : implement Validate() (nothing to do

+ 4 - 2
mcs/class/System.ServiceModel/System.ServiceModel.Description/ContractDescriptionGenerator.cs

@@ -109,8 +109,10 @@ namespace System.ServiceModel.Description
 			} else {
 				foreach (Type t in contracts.Keys)
 					if (t.IsAssignableFrom(givenContractType)) {
-						if (sca != null)
-							throw new InvalidOperationException("The contract type of " + givenContractType + " is ambiguous: can be either " + exactContractType + " or " + t);
+						if (t.IsAssignableFrom (exactContractType)) // exact = IDerived, t = IBase
+							continue;
+						if (sca != null && (exactContractType == null || !exactContractType.IsAssignableFrom (t))) // t = IDerived, exact = IBase
+							throw new InvalidOperationException ("The contract type of " + givenContractType + " is ambiguous: can be either " + exactContractType + " or " + t);
 						exactContractType = t;
 						sca = contracts [t];
 					}

+ 4 - 0
mcs/class/System.ServiceModel/Test/System.ServiceModel.Description/ChangeLog

@@ -1,3 +1,7 @@
+2009-07-02  Atsushi Enomoto  <[email protected]>
+
+	* ContractDescriptionTest.cs : added test for derived contract type.
+
 2009-06-09  Atsushi Enomoto  <[email protected]>
 
 	* ServiceThrottlingBehaviorTest.cs : new.

+ 23 - 1
mcs/class/System.ServiceModel/Test/System.ServiceModel.Description/ContractDescriptionTest.cs

@@ -34,7 +34,7 @@ using System.ServiceModel.Channels;
 using System.ServiceModel.Description;
 using NUnit.Framework;
 
-namespace MonoTests.System.ServiceModel
+namespace MonoTests.System.ServiceModel.Description
 {
 	[TestFixture]
 	public class ContractDescriptionTest
@@ -410,6 +410,13 @@ namespace MonoTests.System.ServiceModel
 				ReleaseInstanceMode.AfterCall, "#5");
 		}
 
+		[Test]
+		public void GetDerivedContract ()
+		{
+			ContractDescription.GetContract (typeof (IFoo3));
+			ContractDescription.GetContract (typeof (Foo3));
+		}
+
 		// It is for testing attribute search in interfaces.
 		public class Foo : IFoo
 		{
@@ -467,6 +474,21 @@ namespace MonoTests.System.ServiceModel
 			Mona NewMona (Mona source);
 		}
 
+		[ServiceContract]
+		public interface IFoo3 : IFoo
+		{
+			[OperationContract]
+			string HeyMan (string msg, string msg2);
+		}
+
+		public class Foo3 : Foo, IFoo3
+		{
+			public string HeyMan (string msg, string msg2)
+			{
+				return msg + msg2;
+			}
+		}
+
 		[ServiceContract]
 		public interface IBar
 		{