Browse Source

2010-06-17 Atsushi Enomoto <[email protected]>

	* ServiceHostBase.cs : retrieve MessageVersion and raise an error
	  if there is none. (Check this earlier than building a listener.)

	* ChannelDispatcher.cs : MessageVersion check is moved to
	  ServiceHostBase.

	* ServiceMetadataExtension.cs : overwrite MessageVersion to use None.
	  (The only special case I found for ChannelDispatcher.MessageVersion.)

	* CustomBindingTest.cs : add tests for MessageVersion check on Open().

	* MetadataExchangeBindingsTest.cs : make sure that special casing of
	  MessageVersion does not happen at this layer.


svn path=/trunk/mcs/; revision=159061
Atsushi Eno 15 years ago
parent
commit
1f4684cd40

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

@@ -1,3 +1,8 @@
+2010-06-17  Atsushi Enomoto  <[email protected]>
+
+	* ServiceMetadataExtension.cs : overwrite MessageVersion to use None.
+	  (The only special case I found for ChannelDispatcher.MessageVersion.)
+
 2010-06-04  Atsushi Enomoto  <[email protected]>
 
 	* OperationDescription.cs : add contract origin flags to identify

+ 1 - 0
mcs/class/System.ServiceModel/System.ServiceModel.Description/ServiceMetadataExtension.cs

@@ -135,6 +135,7 @@ namespace System.ServiceModel.Description
 			};
 
 			var channelDispatcher = new DispatcherBuilder (Owner).BuildChannelDispatcher (owner.Description.ServiceType, se, new BindingParameterCollection ());
+			channelDispatcher.MessageVersion = MessageVersion.None; // it has no MessageVersion.
 			// add HttpGetWsdl to indicate that the ChannelDispatcher is for mex or help.
 			var listener = channelDispatcher.Listener as ChannelListenerBase;
 			if (listener != null)

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

@@ -1,3 +1,8 @@
+2010-06-17  Atsushi Enomoto  <[email protected]>
+
+	* ChannelDispatcher.cs : MessageVersion check is moved to
+	  ServiceHostBase.
+
 2010-06-14  Atsushi Enomoto  <[email protected]>
 
 	* OperationInvokerHandler.cs, MessageProcessingContext.cs :

+ 0 - 4
mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChannelDispatcher.cs

@@ -132,10 +132,6 @@ namespace System.ServiceModel.Dispatcher
 
 		internal EndpointDispatcher InitializeServiceEndpoint (Type serviceType, ServiceEndpoint se)
 		{
-			this.MessageVersion = se.Binding.MessageVersion;
-			if (this.MessageVersion == null)
-				this.MessageVersion = MessageVersion.Default;
-
 			//Attach one EndpointDispacher to the ChannelDispatcher
 			EndpointDispatcher ed = new EndpointDispatcher (se.Address, se.Contract.Name, se.Contract.Namespace);
 			this.Endpoints.Add (ed);

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

@@ -1,3 +1,8 @@
+2010-06-17  Atsushi Enomoto  <[email protected]>
+
+	* ServiceHostBase.cs : retrieve MessageVersion and raise an error
+	  if there is none. (Check this earlier than building a listener.)
+
 2010-06-14  Atsushi Enomoto  <[email protected]>
 
 	* NetTcpBinding.cs : remove pointless EnvelopeVersion field.

+ 5 - 0
mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs

@@ -624,6 +624,10 @@ namespace System.ServiceModel
 			AddBindingParameters (commonParams, se);
 			
 			// See if there's an existing channel that matches this endpoint
+			var version = se.Binding.GetProperty<MessageVersion> (commonParams);
+			if (version == null)
+				throw new InvalidOperationException ("At least one BindingElement in the Binding must override GetProperty method to return a MessageVersion and no prior binding element should return null instead of calling GetInnerProperty method on BindingContext.");
+
 			ChannelDispatcher cd = FindExistingDispatcher (se);
 			EndpointDispatcher ep;
 			if (cd != null) {
@@ -634,6 +638,7 @@ namespace System.ServiceModel
 					ServiceHostBase.CurrentServiceHostHack = host;
 					IChannelListener lf = BuildListener (se, commonParams);
 					cd = new ChannelDispatcher (lf, se.Binding.Name);
+					cd.MessageVersion = version;
 					if (ChannelDispatcherSetter != null) {
 						ChannelDispatcherSetter (cd);
 						ChannelDispatcherSetter = null;

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

@@ -1,3 +1,7 @@
+2010-06-17  Atsushi Enomoto  <[email protected]>
+
+	* CustomBindingTest.cs : add tests for MessageVersion check on Open().
+
 2010-06-15  Atsushi Enomoto  <[email protected]>
 
 	* TcpTransportBindingElementTest.cs : add connection tests (imported

+ 83 - 0
mcs/class/System.ServiceModel/Test/System.ServiceModel.Channels/CustomBindingTest.cs

@@ -274,6 +274,89 @@ namespace MonoTests.System.ServiceModel.Channels
 				new Uri ("http://localhost:8080"), String.Empty, ListenUriMode.Unique);
 			new TextMessageEncodingBindingElement ().BuildChannelListener<IReplyChannel> (ctx);
 		}
+
+		[Test]
+		[ExpectedException (typeof (InvalidOperationException))]
+		public void BuildChannelListenerWithNoMessageVersion ()
+		{
+			// MyBindingElement overrides GetProperty<T>() without calling GetInnerProperty<T>() and returns null in this case.
+			// ServiceHost.Open() tries to get MessageVersion and raises an error if it cannot get any.
+			// HttpTransportBindingElement can actually provide one.
+			ServiceHost host = new ServiceHost (typeof (FooService));
+			host.AddServiceEndpoint (typeof (IFooService),
+				new CustomBinding (new MyBindingElement (false), new HttpTransportBindingElement ()),
+				"http://localhost:8080");
+			host.Open ();
+		}
+
+		[Test]
+		[ExpectedException (typeof (MyException))]
+		public void BuildChannelListenerWithMessageVersion ()
+		{
+			// MyBindingElement overrides GetProperty<T>() to call GetInnerProperty<T>() (default implementation).
+			// HttpTransportBindingElement should return Soap11.
+			ServiceHost host = new ServiceHost (typeof (FooService));
+			host.AddServiceEndpoint (typeof (IFooService),
+				new CustomBinding (new MyBindingElement (true), new HttpTransportBindingElement ()),
+				"http://localhost:8080");
+			host.Open ();
+			host.Close ();
+		}
+		
+		[ServiceContract]
+		public interface IFooService
+		{
+			[OperationContract]
+			string Hello (string msg);
+		}
+		public class FooService : IFooService
+		{
+			public string Hello (string msg)
+			{
+				return "hello";
+			}
+		}
+
+		class MyBindingElement : BindingElement
+		{
+			public MyBindingElement (bool returnProperty)
+			{
+				return_property = returnProperty;
+			}
+			
+			bool return_property;
+
+			public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (
+				BindingContext ctx)
+			{
+				throw new NotImplementedException ();
+			}
+
+			public override IChannelListener<TChannel> BuildChannelListener<TChannel> (
+				BindingContext ctx)
+			{
+				throw new MyException ();
+			}
+
+			public override bool CanBuildChannelListener<TChannel> (BindingContext ctx)
+			{
+				return true;
+			}
+
+			public override BindingElement Clone ()
+			{
+				return new MyBindingElement (return_property);
+			}
+
+			public override T GetProperty<T> (BindingContext context)
+			{
+				return return_property ? context.GetInnerProperty<T> () : null;
+			}
+		}
+		
+		public class MyException : Exception
+		{
+		}
 	}
 
 	[DataContract (Namespace = "urn:foo")]

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

@@ -1,3 +1,8 @@
+2010-06-17  Atsushi Enomoto  <[email protected]>
+
+	* MetadataExchangeBindingsTest.cs : make sure that special casing of
+	  MessageVersion does not happen at this layer.
+
 2010-04-05  Atsushi Enomoto  <[email protected]>
 
 	* WsdlExporterTest.cs : fixed and enabled some working tests.

+ 31 - 0
mcs/class/System.ServiceModel/Test/System.ServiceModel.Description/MetadataExchangeBindingsTest.cs

@@ -34,6 +34,7 @@ using System.Runtime.Serialization;
 using System.ServiceModel;
 using System.ServiceModel.Channels;
 using System.ServiceModel.Description;
+using System.ServiceModel.Dispatcher;
 
 using NUnit.Framework;
 
@@ -54,6 +55,36 @@ namespace MonoTests.System.ServiceModel.Description
 			Assert.IsTrue (b.CreateBindingElements ().Any (be => be is TransactionFlowBindingElement), "#b2");
 			Assert.IsFalse (b.CreateBindingElements ().Any (be => be is ReliableSessionBindingElement), "#b3");
 			Assert.IsTrue (new TransactionFlowBindingElement ().TransactionProtocol == TransactionProtocol.Default, "#x1");
+			Assert.AreEqual (MessageVersion.Soap12WSAddressing10, b.MessageVersion, "#5");
+			Assert.AreEqual (MessageVersion.Soap12WSAddressing10, b.GetProperty<MessageVersion> (new BindingParameterCollection ()), "#6");
+
+			var host = new ServiceHost (typeof (MetadataExchange));
+			host.AddServiceEndpoint (typeof (IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding (), new Uri ("http://localhost:8080"));
+			host.Open ();
+			try {
+				// it still does not rewrite MessageVersion.None. It's rather likely ServiceMetadataExtension which does overwriting.
+				Assert.AreEqual (MessageVersion.Soap12WSAddressing10, ((ChannelDispatcher) host.ChannelDispatchers [0]).MessageVersion, "#7");
+			} finally {
+				host.Close ();
+			}
+		}
+		
+		public class MetadataExchange : IMetadataExchange
+		{
+			public Message Get (Message request)
+			{
+				throw new Exception ();
+			}
+			
+			public IAsyncResult BeginGet (Message request, AsyncCallback callback, object state)
+			{
+				throw new Exception ();
+			}
+			
+			public Message EndGet (IAsyncResult result)
+			{
+				throw new Exception ();
+			}
 		}
 	}
 }