From 655112693475ef1ca38f6538badabb620d494688 Mon Sep 17 00:00:00 2001 From: eeichinger Date: Wed, 4 Mar 2009 23:29:19 +0000 Subject: [PATCH] fixed SPRNET-1179 --- .../ServiceModel/ServiceExporter.cs | 16 +++++---- .../ServiceModel/ServiceExporterTests.cs | 34 ++++++++++++++++++- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/Spring/Spring.Services/ServiceModel/ServiceExporter.cs b/src/Spring/Spring.Services/ServiceModel/ServiceExporter.cs index 2f717dcb..27faeca6 100644 --- a/src/Spring/Spring.Services/ServiceModel/ServiceExporter.cs +++ b/src/Spring/Spring.Services/ServiceModel/ServiceExporter.cs @@ -357,6 +357,7 @@ namespace Spring.ServiceModel { IProxyTypeBuilder builder = new ConfigurableServiceProxyTypeBuilder(TargetName, this.objectName, objectFactory, Name, Namespace, ConfigurationName, CallbackContract, ProtectionLevel, SessionMode); + if (ContractInterface != null) { builder.Interfaces = new Type[] { ContractInterface }; @@ -364,6 +365,13 @@ namespace Spring.ServiceModel builder.TypeAttributes = TypeAttributes; builder.MemberAttributes = MemberAttributes; + if (builder.Interfaces.Length > 1) + { + throw new ArgumentException(String.Format( + "ServiceExporter cannot export service type '{0}' as a WCF service because it implements multiple interfaces. Specify the contract interface to expose via the ContractInterface property.", + builder.TargetType)); + } + proxyType = builder.BuildProxyType(); } @@ -382,6 +390,7 @@ namespace Spring.ServiceModel string name, string ns, string configurationName, Type callbackContract, ProtectionLevel protectionLevel, SessionMode sessionMode) : base(targetName, objectName, objectFactory) { + if (!StringUtils.HasText(configurationName)) { name = this.Interfaces[0].Name; @@ -476,13 +485,6 @@ namespace Spring.ServiceModel { Type[] proxiableInterfaces = base.GetProxiableInterfaces(interfaces); - if (proxiableInterfaces.Length > 1) - { - throw new ArgumentException(String.Format( - "ServiceExporter cannot export service type '{0}' as a WCF service because it implements multiple interfaces. Specify the contract interface to expose via the ContractInterface property.", - this.TargetType)); - } - return proxiableInterfaces; } } diff --git a/test/Spring/Spring.Services.Tests/ServiceModel/ServiceExporterTests.cs b/test/Spring/Spring.Services.Tests/ServiceModel/ServiceExporterTests.cs index b2358b45..5b3444e6 100644 --- a/test/Spring/Spring.Services.Tests/ServiceModel/ServiceExporterTests.cs +++ b/test/Spring/Spring.Services.Tests/ServiceModel/ServiceExporterTests.cs @@ -29,6 +29,7 @@ using System.Net.Security; using System.ServiceModel; using NUnit.Framework; +using Spring.Objects.Factory.Config; using Spring.ServiceModel; using Spring.Core.IO; using Spring.Objects.Factory; @@ -54,6 +55,7 @@ namespace Spring.ServiceModel @" + "; Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)); @@ -83,6 +85,29 @@ namespace Spring.ServiceModel Assert.IsTrue(typeof(IContract).IsAssignableFrom(proxyType)); } + [Test(Description = "http://jira.springframework.org/browse/SPRNET-1179")] + public void ProxiesOnlyContractInterface() + { + se.ObjectName = "ProxiesOnlyContractInterface"; + se.TargetName = "serviceWithMultipleInterfaces"; + se.ContractInterface = typeof(IContract); + se.AfterPropertiesSet(); + + Type proxyType = se.GetObject() as Type; + Assert.IsNotNull(proxyType); + Assert.IsTrue(typeof(IContract).IsAssignableFrom(proxyType)); + } + + [Test(Description = "http://jira.springframework.org/browse/SPRNET-1179")] + [ExpectedException(typeof(ArgumentException), ExpectedMessage = "ServiceExporter cannot export service type 'Spring.ServiceModel.ServiceExporterTests+ServiceWithMultipleInterfaces' as a WCF service because it implements multiple interfaces. Specify the contract interface to expose via the ContractInterface property.")] + public void ProxiesOnlyContractInterfaceFailsIfNoContractInterface() + { + se.ObjectName = "ProxiesOnlyContractInterface"; + se.TargetName = "serviceWithMultipleInterfaces"; + // se.ContractInterface = typeof (IContract); + se.AfterPropertiesSet(); + } + [Test] public void ProxyTypeEqualsObjectName() { @@ -128,7 +153,7 @@ namespace Spring.ServiceModel se.Namespace = "http://Spring.Services.Tests"; se.ProtectionLevel = ProtectionLevel.Sign; se.SessionMode = SessionMode.Required; - + se.AfterPropertiesSet(); Type proxyType = se.GetObject() as Type; @@ -231,6 +256,9 @@ namespace Spring.ServiceModel string SomeMethod(int param); } + public interface IOtherContract + { } + public class Service : IContract { public string SomeMethod(int param) @@ -239,6 +267,10 @@ namespace Spring.ServiceModel } } + public class ServiceWithMultipleInterfaces : Service, IOtherContract + { + } + [ServiceContract(Namespace = "http://Spring.Services.Tests")] public class DecoratedService : IContract {