fixed SPRNET-1179
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@"<?xml version='1.0' encoding='UTF-8' ?>
|
||||
<objects xmlns='http://www.springframework.net'>
|
||||
<object id='service' type='Spring.ServiceModel.ServiceExporterTests+Service, Spring.Services.Tests'/>
|
||||
<object id='serviceWithMultipleInterfaces' type='Spring.ServiceModel.ServiceExporterTests+ServiceWithMultipleInterfaces, Spring.Services.Tests'/>
|
||||
<object id='decoratedService' type='Spring.ServiceModel.ServiceExporterTests+DecoratedService, Spring.Services.Tests'/>
|
||||
</objects>";
|
||||
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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user