Przeglądaj źródła

ChannelFactory<T> and ClientBase<T> do not reject ServiceEndpoint with null Binding or Address.

Atsushi Eno 15 lat temu
rodzic
commit
5d72c8a3a2

+ 10 - 2
mcs/class/System.ServiceModel/System.ServiceModel/ClientBase.cs

@@ -151,30 +151,38 @@ namespace System.ServiceModel
 
 #if NET_4_0
 		protected ClientBase (ServiceEndpoint endpoint)
-			: this (endpoint.Binding, endpoint.Address)
+			: this (null, endpoint)
 		{
 		}
 
 		protected ClientBase (InstanceContext instance, ServiceEndpoint endpoint)
-			: this (instance, endpoint.Binding, endpoint.Address)
+			: this (instance, new ChannelFactory<TChannel> (endpoint))
 		{
 		}
 #endif
 
 		internal ClientBase (ChannelFactory<TChannel> factory)
+			: this (null, factory)
 		{
+		}
+
+		internal ClientBase (InstanceContext instance, ChannelFactory<TChannel> factory)
+		{
+			// FIXME: use instance
 			ChannelFactory = factory;
 		}
 
 		internal virtual void Initialize (InstanceContext instance,
 			string endpointConfigurationName, EndpointAddress remoteAddress)
 		{
+			// FIXME: use instance
 			ChannelFactory = new ChannelFactory<TChannel> (endpointConfigurationName, remoteAddress);
 		}
 
 		internal virtual void Initialize (InstanceContext instance,
 			Binding binding, EndpointAddress remoteAddress)
 		{
+			// FIXME: use instance
 			ChannelFactory = new ChannelFactory<TChannel> (binding, remoteAddress);
 		}
 

+ 9 - 0
mcs/class/System.ServiceModel/Test/System.ServiceModel/ChannelFactory_1Test.cs

@@ -431,6 +431,15 @@ namespace MonoTests.System.ServiceModel
 			Assert.AreEqual ("callResult", res.val, "#2");
 		}
 
+#if NET_4_0
+		[Test]
+		public void ConstructorServiceEndpoint ()
+		{
+			// It is okay to pass ServiceEndpoint that does not have Binding or EndpointAddress.
+			new ChannelFactory<IRequestChannel> (new ServiceEndpoint (ContractDescription.GetContract (typeof (IMetadataExchange)), null, null));
+		}
+#endif
+
 		public T CreateFooComplexMC_Channel<T> (bool isXml)
 		{
 			return CreateChannel<T> (

+ 27 - 0
mcs/class/System.ServiceModel/Test/System.ServiceModel/ClientBaseTest.cs

@@ -473,5 +473,32 @@ namespace MonoTests.System.ServiceModel
 				throw new NotImplementedException ();
 			}
 		}
+
+#if NET_4_0
+		[Test]
+		public void ConstructorServiceEndpoint ()
+		{
+			// It is okay to pass ServiceEndpoint that does not have Binding or EndpointAddress.
+			new MyClient (new ServiceEndpoint (ContractDescription.GetContract (typeof (IMetadataExchange)), null, null));
+			try {
+				new MyClient ((Binding) null, (EndpointAddress) null);
+				Assert.Fail ("ArgumentNullException is expected");
+			} catch (ArgumentNullException) {
+			}
+		}
+
+		class MyClient : ClientBase<IMetadataExchange>
+		{
+			public MyClient (ServiceEndpoint endpoint)
+				: base (endpoint)
+			{
+			}
+			
+			public MyClient (Binding binding, EndpointAddress address)
+				: base (binding, address)
+			{
+			}
+		}
+#endif
 	}
 }