Add namespace parser for WCF integration [SPRNET-1324]

This commit is contained in:
bbaia
2010-04-14 14:57:28 +00:00
parent 097bda93bd
commit 9551238d09
25 changed files with 699 additions and 31 deletions

View File

@@ -1241,6 +1241,9 @@ Commandline Examples:
<copy todir="${current.package.dir}/doc/schema"
file="src/Spring/Spring.Services/Remoting/Config/spring-remoting-1.1.xsd"/>
<copy todir="${current.package.dir}/doc/schema"
file="src/Spring/Spring.Services/ServiceModel/Config/spring-wcf-1.3.xsd"/>
<copy todir="${current.package.dir}/doc/schema"
file="src/Spring/Spring.Messaging.Nms/Messaging/Nms/Config/spring-nms-1.3.xsd"/>

View File

@@ -9,13 +9,16 @@
</configSections>
<spring>
<context>
<!-- Make sure 'http://localhost:2637/Spring.WcfQuickStart.ServerWeb/' web application is running -->
<resource uri="assembly://Spring.WcfQuickStart.ClientApp/Spring.WcfQuickStart.Config/ServerWeb.xml"/>
<!-- Make sure 'Spring.WcfQuickStart.ServerApp' console application is running and listening. -->
<resource uri="assembly://Spring.WcfQuickStart.ClientApp/Spring.WcfQuickStart.Config/ServerApp.xml"/>
<!-- Aspects definition -->
<resource uri="assembly://Spring.WcfQuickStart.ClientApp/Spring.WcfQuickStart.Config/Aspects.xml"/>
</context>
</spring>

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:aop="http://www.springframework.net/aop">
<!--<object id="serviceOperation" type="Spring.Aop.Support.SdkRegularExpressionMethodPointcut, Spring.Aop">
<property name="pattern" value="Spring.WcfQuickStart.*"/>
</object>
<object id="perfAdvice" type="Spring.WcfQuickStart.SimplePerformanceInterceptor, Spring.WcfQuickStart.Aspects">
<property name="Prefix" value="Service Layer Performance"/>
</object>
<aop:config>
<aop:advisor pointcut-ref="serviceOperation" advice-ref="perfAdvice"/>
</aop:config>-->
<!-- Or using new TypeNameAutoProxyCreator -->
<object id="perfAdvice" type="Spring.WcfQuickStart.SimplePerformanceInterceptor, Spring.WcfQuickStart.Aspects">
<property name="Prefix" value="Service Layer Performance"/>
</object>
<object type="Spring.Aop.Framework.AutoProxy.TypeNameAutoProxyCreator, Spring.Aop">
<property name="TypeNames">
<list>
<value>Spring.WcfQuickStart.*</value>
</list>
</property>
<property name="InterceptorNames">
<list>
<value>perfAdvice</value>
</list>
</property>
</object>
</objects>

View File

@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<objects xmlns="http://www.springframework.net"
xmlns:wcf="http://www.springframework.net/wcf">
<!-- Old fashion way -->
<!-- returns ChannelFactory<ICalculator>("calculatorEndpoint").CreateChannel() -->
<object id="serverAppCalculator"
<!--<object id="serverAppCalculator"
type="Spring.WcfQuickStart.ICalculator, Spring.WcfQuickStart.Contracts"
factory-object="serverAppCalculatorChannelFactory"
factory-method="CreateChannel" />
@@ -10,7 +12,11 @@
<object id="serverAppCalculatorChannelFactory"
type="System.ServiceModel.ChannelFactory&lt;Spring.WcfQuickStart.ICalculator>, System.ServiceModel">
<constructor-arg name="endpointConfigurationName" value="serverAppCalculatorEndpoint" />
</object>
</object>-->
<wcf:channelFactory id="serverAppCalculator"
channelType="Spring.WcfQuickStart.ICalculator, Spring.WcfQuickStart.Contracts"
endpointConfigurationName="serverAppCalculatorEndpoint" />
</objects>

View File

@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<objects xmlns="http://www.springframework.net"
xmlns:wcf="http://www.springframework.net/wcf">
<!-- Old fashion way -->
<!-- returns ChannelFactory<ICalculator>("calculatorEndpoint").CreateChannel() -->
<object id="serverWebCalculator"
<!--<object id="serverWebCalculator"
type="Spring.WcfQuickStart.ICalculator, Spring.WcfQuickStart.Contracts"
factory-object="serverWebCalculatorChannelFactory"
factory-method="CreateChannel" />
@@ -10,8 +12,13 @@
<object id="serverWebCalculatorChannelFactory"
type="System.ServiceModel.ChannelFactory&lt;Spring.WcfQuickStart.ICalculator>, System.ServiceModel">
<constructor-arg name="endpointConfigurationName" value="serverWebCalculatorEndpoint" />
</object>
</object>-->
<wcf:channelFactory id="serverWebCalculator"
channelType="Spring.WcfQuickStart.ICalculator, Spring.WcfQuickStart.Contracts"
endpointConfigurationName="serverWebCalculatorEndpoint">
<!-- You can use classic DI to configure the ChannelFactory<T> instance -->
<wcf:property name="Credentials.Windows.ClientCredential" value="Domain\Login:Password" />
</wcf:channelFactory>
</objects>

View File

@@ -52,6 +52,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Spring.Aop, Version=0.0.0.20468, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Spring.Aop.dll</HintPath>
</Reference>
<Reference Include="Spring.Core, Version=1.2.0.20311, Culture=neutral, PublicKeyToken=65e474d141e25e07, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\net\2.0\debug\Spring.Core.dll</HintPath>
@@ -96,11 +100,18 @@
<EmbeddedResource Include="Config\ServerWeb.xml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Spring.WcfQuickStart.Aspects\Spring.WcfQuickStart.Aspects.csproj">
<Project>{B52BBAA3-1B30-4905-827C-1D81EBA56A15}</Project>
<Name>Spring.WcfQuickStart.Aspects</Name>
</ProjectReference>
<ProjectReference Include="..\Spring.WcfQuickStart.Contracts\Spring.WcfQuickStart.Contracts.csproj">
<Project>{53263837-0643-45FE-96A2-46D425E1A36F}</Project>
<Name>Spring.WcfQuickStart.Contracts</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Config\Aspects.xml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -5,7 +5,6 @@
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
</sectionGroup>
</configSections>
@@ -15,14 +14,6 @@
<context>
<resource uri="config://spring/objects"/>
</context>
<parsers>
<!-- <parser namespace="http://www.springframework.net/aop"-->
<!-- type="Spring.Aop.Config.AopNamespaceParser, Spring.Aop"-->
<!-- schemaLocation="assembly://Spring.Aop/Spring.Aop.Config/spring-aop-1.1.xsd" />-->
</parsers>
<objects xmlns="http://www.springframework.net"
xmlns:aop="http://www.springframework.net/aop">

View File

@@ -100,6 +100,7 @@ namespace Spring.Objects.Factory.Xml
wellknownNamespaceParserTypeNames["http://www.springframework.net/aop"] = "Spring.Aop.Config.AopNamespaceParser, Spring.Aop";
wellknownNamespaceParserTypeNames["http://www.springframework.net/db"] = "Spring.Data.Config.DatabaseNamespaceParser, Spring.Data";
wellknownNamespaceParserTypeNames["http://www.springframework.net/remoting"] = "Spring.Remoting.Config.RemotingNamespaceParser, Spring.Services";
wellknownNamespaceParserTypeNames["http://www.springframework.net/wcf"] = "Spring.ServiceModel.Config.WcfNamespaceParser, Spring.Services";
wellknownNamespaceParserTypeNames["http://www.springframework.net/nms"] = "Spring.Messaging.Nms.Config.NmsNamespaceParser, Spring.Messaging.Nms";
wellknownNamespaceParserTypeNames["http://www.springframework.net/ems"] = "Spring.Messaging.Ems.Config.EmsNamespaceParser, Spring.Messaging.Ems";
wellknownNamespaceParserTypeNames["http://www.springframework.net/validation"] = "Spring.Validation.Config.ValidationNamespaceParser, Spring.Core";

View File

@@ -0,0 +1,121 @@
#if NET_3_0
#region License
/*
* Copyright © 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.ServiceModel;
using Spring.Objects.Factory;
#endregion
namespace Spring.ServiceModel
{
/// <summary>
/// <see cref="IFactoryObject"/> that creates a channel that is used by clients
/// to send messages to a specified endpoint address.
/// </summary>
/// <typeparam name="T">The type of channel produced by the channel factory.</typeparam>
/// <author>Bruno Baia</author>
public class ChannelFactoryObject<T> : ChannelFactory<T>, IFactoryObject
{
#region Logging
private static readonly Common.Logging.ILog Log = Common.Logging.LogManager.GetLogger(typeof(ChannelFactoryObject<>));
#endregion
private bool _isSingleton = true;
private string _endpointConfigurationName;
/// <summary>
/// Creates a new instance of the <see cref="ChannelFactoryObject{T}"/> class.
/// </summary>
/// <param name="endpointConfigurationName">
/// The configuration name used for the endpoint.
/// </param>
public ChannelFactoryObject(string endpointConfigurationName)
: base(endpointConfigurationName)
{
this._endpointConfigurationName = endpointConfigurationName;
}
/// <summary>
/// Gets the configuration name used for the endpoint.
/// </summary>
public string EndpointConfigurationName
{
get { return this._endpointConfigurationName; }
}
#region IFactoryObject Membres
/// <summary>
/// Return an instance (possibly shared or independent) of the channel
/// managed by this factory.
/// </summary>
/// <returns>
/// An instance (possibly shared or independent) of the channel managed by
/// this factory.
/// </returns>
public object GetObject()
{
#region Instrumentation
if (Log.IsDebugEnabled)
{
Log.Debug(String.Format(
"Creating channel of type '{0}' for the specified endpoint '{1}'...",
typeof(T).FullName, this._endpointConfigurationName));
}
#endregion
return this.CreateChannel();
}
/// <summary>
/// Return the <see cref="System.Type"/> of channel that this
/// <see cref="Spring.Objects.Factory.IFactoryObject"/> creates.
/// </summary>
public Type ObjectType
{
get { return typeof(T); }
}
/// <summary>
/// Is the object managed by this factory a singleton or a prototype ?
/// </summary>
/// <remarks>
/// Default value is <see langword="true"/>.
/// </remarks>
public bool IsSingleton
{
get { return this._isSingleton; }
set { this._isSingleton = value; }
}
#endregion
}
}
#endif

View File

@@ -0,0 +1,108 @@
#if NET_3_0
#region License
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Xml;
using Spring.Util;
using Spring.Objects.Factory.Xml;
using Spring.Objects.Factory.Config;
using Spring.Objects.Factory.Support;
using Spring.Core.TypeResolution;
using Spring.Objects;
#endregion
namespace Spring.ServiceModel.Config
{
/// <summary>
/// The <see cref="IObjectDefinitionParser"/> for the <code>&lt;wcf:channelFactory&gt;</code> tag.
/// </summary>
/// <author>Bruno Baia</author>
public class ChannelFactoryObjectDefinitionParser : ObjectsNamespaceParser, IObjectDefinitionParser
{
private static readonly string ChannelTypeAttribute = "channelType";
private static readonly string EndpointConfigurationNameAttribute = "endpointConfigurationName";
#region IObjectDefinitionParser Members
/// <summary>
/// Parse the specified XmlElement and register the resulting
/// ObjectDefinitions with the <see cref="ParserContext.Registry"/> IObjectDefinitionRegistry
/// embedded in the supplied <see cref="ParserContext"/>
/// </summary>
/// <param name="element">The element to be parsed.</param>
/// <param name="parserContext">The object encapsulating the current state of the parsing process.
/// Provides access to a IObjectDefinitionRegistry</param>
/// <returns>The primary object definition.</returns>
/// <remarks>
/// <p>
/// This method is never invoked if the parser is namespace aware
/// and was called to process the root node.
/// </p>
/// </remarks>
IObjectDefinition IObjectDefinitionParser.ParseElement(XmlElement element, ParserContext parserContext)
{
AssertUtils.ArgumentNotNull(parserContext, "parserContext");
string id = element.GetAttribute(ObjectDefinitionConstants.IdAttribute);
string unresolvedChannelType = element.GetAttribute(ChannelTypeAttribute);
string endpointConfigurationName = element.GetAttribute(EndpointConfigurationNameAttribute);
IObjectDefinition channelFactoryDefinition;
try
{
Type channelType = TypeResolutionUtils.ResolveType(unresolvedChannelType);
Type channelFactoryType = typeof(ChannelFactoryObject<>).MakeGenericType(new Type[1] { channelType });
channelFactoryDefinition = new RootObjectDefinition(channelFactoryType);
}
catch
{
// Try to resolve type later (Can be a type alias)
channelFactoryDefinition = new RootObjectDefinition(
String.Format("Spring.ServiceModel.ChannelFactoryObject<{0}>, Spring.Services", unresolvedChannelType),
new ConstructorArgumentValues(),
new MutablePropertyValues());
}
if (!StringUtils.HasText(id))
{
id = parserContext.ReaderContext.GenerateObjectName(channelFactoryDefinition);
}
channelFactoryDefinition.ConstructorArgumentValues.AddNamedArgumentValue("endpointConfigurationName", endpointConfigurationName);
foreach (PropertyValue pv in base.ParsePropertyElements(id, element, parserContext))
{
channelFactoryDefinition.PropertyValues.Add(pv);
}
parserContext.Registry.RegisterObjectDefinition(id, channelFactoryDefinition);
return null;
}
#endregion
}
}
#endif

View File

@@ -0,0 +1,55 @@
#if NET_3_0
#region License
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using Spring.Objects.Factory.Xml;
#endregion
namespace Spring.ServiceModel.Config
{
/// <summary>
/// Namespace parser for the WCF namespace.
/// </summary>
/// <author>Bruno Baia</author>
[
NamespaceParser(
Namespace = "http://www.springframework.net/wcf",
SchemaLocationAssemblyHint = typeof(WcfNamespaceParser),
SchemaLocation = "/Spring.ServiceModel.Config/spring-wcf-1.3.xsd")
]
public sealed class WcfNamespaceParser : NamespaceParserSupport
{
private const string ChannelFactoryElement = "channelFactory";
private const string ServiceHostElement = "serviceHost";
private const string ServiceExporterElement = "serviceExporter";
/// <summary>
/// Register the <see cref="IObjectDefinitionParser"/> for the WCF tags.
/// </summary>
public override void Init()
{
RegisterObjectDefinitionParser(ChannelFactoryElement, new ChannelFactoryObjectDefinitionParser());
}
}
}
#endif

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns="http://www.springframework.net/wcf"
xmlns:objects="http://www.springframework.net"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:vs="http://schemas.microsoft.com/Visual-Studio-Intellisense"
targetNamespace="http://www.springframework.net/wcf"
elementFormDefault="qualified" attributeFormDefault="unqualified"
vs:friendlyname="Spring.NET WCF Framework Configuration" vs:ishtmlschema="false" vs:iscasesensitive="true" vs:requireattributequotes="true" vs:defaultnamespacequalifier="" vs:defaultnsprefix="">
<xsd:import namespace="http://www.springframework.net"/>
<xsd:annotation>
<xsd:documentation>
<![CDATA[
Defines the configuration elements for the Spring Framework's WCF support.
]]>
</xsd:documentation>
</xsd:annotation>
<xsd:complexType name="channelFactoryType">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
Creates a channel that is used by clients to send messages to a specified endpoint address.
]]>
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="property" type="objects:property" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
Defines properties of the factory that creates the channel.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" use="optional">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
The id of the created object.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="channelType" type="objects:nonNullString" use="required">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
The type of channel produced by this channel factory.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="endpointConfigurationName" type="objects:nonNullString" use="required">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
The configuration name in the application configuration file used for the endpoint.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:element name="channelFactory" type="channelFactoryType"/>
</xsd:schema>

View File

@@ -49,7 +49,7 @@ namespace Spring.ServiceModel
{
#region Logging
private static readonly Common.Logging.ILog LOG = Common.Logging.LogManager.GetLogger(typeof(ServiceExporter));
//private static readonly Common.Logging.ILog LOG = Common.Logging.LogManager.GetLogger(typeof(ServiceExporter));
#endregion

View File

@@ -30,7 +30,7 @@
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE;DEBUG;NET_2_0;NET_3_0</DefineConstants>
<DefineConstants>TRACE;DEBUG;NET_2_0</DefineConstants>
<DocumentationFile>Spring.Services.xml</DocumentationFile>
<DebugSymbols>true</DebugSymbols>
<FileAlignment>4096</FileAlignment>
@@ -83,7 +83,6 @@
<Reference Include="System.EnterpriseServices">
<Name>system.enterpriseservices</Name>
</Reference>
<Reference Include="System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
<Reference Include="System.Web.Services">
<Name>system.web.services</Name>
</Reference>
@@ -125,11 +124,6 @@
<Compile Include="Remoting\SaoFactoryObject.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="ServiceModel\Activation\ServiceHostFactory.cs" />
<Compile Include="ServiceModel\Activation\ServiceHostFactoryObject.cs" />
<Compile Include="ServiceModel\ServiceExporter.cs" />
<Compile Include="ServiceModel\SpringServiceHost.cs" />
<Compile Include="ServiceModel\Support\ServiceProxyTypeBuilder.cs" />
<Compile Include="Web\Services\WebServiceProxyFactory.cs">
<SubType>Code</SubType>
</Compile>

View File

@@ -131,6 +131,9 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="ServiceModel\Activation\ServiceHostFactoryObject.cs" />
<Compile Include="ServiceModel\ChannelFactoryObject.cs" />
<Compile Include="ServiceModel\Config\ChannelFactoryObjectDefinitionParser.cs" />
<Compile Include="ServiceModel\Config\WcfNamespaceParser.cs" />
<Compile Include="ServiceModel\ServiceExporter.cs" />
<Compile Include="ServiceModel\SpringServiceHost.cs" />
<Compile Include="ServiceModel\Support\ServiceProxyTypeBuilder.cs" />
@@ -142,6 +145,7 @@
<SubType>
</SubType>
</EmbeddedResource>
<EmbeddedResource Include="ServiceModel\Config\spring-wcf-1.3.xsd" />
<None Include="Spring.Services.build" />
</ItemGroup>
<ItemGroup>

View File

@@ -57,6 +57,9 @@
<resources basedir="." prefix="Spring.Remoting.Config">
<include name="Remoting/Config/spring-remoting-1.1.xsd" />
</resources>
<resources basedir="." prefix="Spring.ServiceModel.Config">
<include if="${net-3.0.installed and net-3.0}" name="ServiceModel/Config/spring-wcf-1.3.xsd" />
</resources>
<resources prefix="Spring" dynamicprefix="true" failonempty="true">
<include name="**/*.keys" />
<exclude name="**/obj/**" />
@@ -67,8 +70,7 @@
<include name="Spring.Aop.dll" />
<include name="Spring.Web.dll" />
<include name="System.Web.Services.dll" />
<include if="${net-3.0.installed and net-3.0}" name="${net-3.0.ReferenceInstallPath}\System.ServiceModel.dll" />-->
<include if="${net-3.0.installed and net-3.0}" name="${net-3.0.ReferenceInstallPath}\System.ServiceModel.dll" />
</references>
</csc>
</target>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:wcf="http://www.springframework.net/wcf">
<wcf:channelFactory id="channel"
channelType="Spring.ServiceModel.Config.ChannelFactoryObjectDefinitionParserTests+IContract, Spring.Services.Tests"
endpointConfigurationName="ecn" />
</objects>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:wcf="http://www.springframework.net/wcf">
<wcf:channelFactory id="channel"
channelType="Spring.ServiceModel.Config.ChannelFactoryObjectDefinitionParserTests+IContract, Spring.Services.Tests"
endpointConfigurationName="ecn">
<wcf:property name="Credentials.Windows.ClientCredential" value="Spring\Bruno:gnirpS" />
</wcf:channelFactory>
</objects>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:wcf="http://www.springframework.net/wcf">
<object type="Spring.Objects.Factory.Config.TypeAliasConfigurer, Spring.Core">
<property name="TypeAliases">
<dictionary>
<entry key="IContract" value="Spring.ServiceModel.Config.ChannelFactoryObjectDefinitionParserTests+IContract, Spring.Services.Tests" />
</dictionary>
</property>
</object>
<wcf:channelFactory id="channel"
channelType="IContract"
endpointConfigurationName="ecn" />
</objects>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:wcf="http://www.springframework.net/wcf">
<wcf:channelFactory channelType="Spring.ServiceModel.Config.ChannelFactoryObjectDefinitionParserTests+IContract, Spring.Services.Tests"
endpointConfigurationName="ecn" />
</objects>

View File

@@ -0,0 +1,149 @@
#if NET_3_0
#region License
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System.Collections;
using System.ServiceModel;
using Spring.Context;
using Spring.Context.Support;
using Spring.Objects.Factory.Xml;
using Spring.Objects.Factory.Support;
using NUnit.Framework;
#endregion
namespace Spring.ServiceModel.Config
{
/// <summary>
/// Unit tests for the <see cref="ChannelFactoryObjectDefinitionParser"/> class.
/// </summary>
/// <author>Bruno Baia</author>
[TestFixture]
public class ChannelFactoryObjectDefinitionParserTests
{
[Test]
public void BasicConfig()
{
NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser));
IApplicationContext ctx = new XmlApplicationContext(
ReadOnlyXmlTestResource.GetFilePath("ChannelFactoryObjectDefinitionParserTests.BasicConfig.xml", this.GetType()));
Assert.IsTrue(ctx.ContainsObjectDefinition("channel"));
RootObjectDefinition rod = ((IObjectDefinitionRegistry)ctx).GetObjectDefinition("channel") as RootObjectDefinition;
Assert.IsNotNull(rod);
Assert.IsTrue(rod.HasObjectType);
Assert.AreEqual(typeof(ChannelFactoryObject<IContract>), rod.ObjectType);
Assert.AreEqual(1, rod.ConstructorArgumentValues.NamedArgumentValues.Count);
Assert.AreEqual("ecn", rod.ConstructorArgumentValues.GetNamedArgumentValue("endpointConfigurationName").Value);
ChannelFactoryObject<IContract> cfo = ctx.GetObject("&channel") as ChannelFactoryObject<IContract>;
Assert.IsNotNull(cfo);
Assert.AreEqual(typeof(IContract), cfo.ObjectType);
IContract contract = ctx.GetObject("channel") as IContract;
Assert.IsNotNull(contract);
}
[Test]
public void CustomProperties()
{
NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser));
IApplicationContext ctx = new XmlApplicationContext(
ReadOnlyXmlTestResource.GetFilePath("ChannelFactoryObjectDefinitionParserTests.CustomProperties.xml", this.GetType()));
Assert.IsTrue(ctx.ContainsObjectDefinition("channel"));
RootObjectDefinition rod = ((IObjectDefinitionRegistry)ctx).GetObjectDefinition("channel") as RootObjectDefinition;
Assert.IsNotNull(rod);
Assert.IsTrue(rod.HasObjectType);
Assert.AreEqual(typeof(ChannelFactoryObject<IContract>), rod.ObjectType);
Assert.AreEqual(1, rod.ConstructorArgumentValues.NamedArgumentValues.Count);
Assert.AreEqual("ecn", rod.ConstructorArgumentValues.GetNamedArgumentValue("endpointConfigurationName").Value);
Assert.IsTrue(rod.PropertyValues.Contains("Credentials.Windows.ClientCredential"));
Assert.AreEqual("Spring\\Bruno:gnirpS", rod.PropertyValues.GetPropertyValue("Credentials.Windows.ClientCredential").Value);
ChannelFactoryObject<IContract> cfo = ctx.GetObject("&channel") as ChannelFactoryObject<IContract>;
Assert.IsNotNull(cfo);
Assert.AreEqual(typeof(IContract), cfo.ObjectType);
Assert.AreEqual("Spring", cfo.Credentials.Windows.ClientCredential.Domain);
Assert.AreEqual("Bruno", cfo.Credentials.Windows.ClientCredential.UserName);
Assert.AreEqual("gnirpS", cfo.Credentials.Windows.ClientCredential.Password);
IContract contract = ctx.GetObject("channel") as IContract;
Assert.IsNotNull(contract);
}
[Test]
public void WithoutId()
{
NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser));
IApplicationContext ctx = new XmlApplicationContext(
ReadOnlyXmlTestResource.GetFilePath("ChannelFactoryObjectDefinitionParserTests.WithoutId.xml", this.GetType()));
IDictionary channels = ctx.GetObjectsOfType(typeof(IContract));
Assert.AreEqual(1, channels.Count);
}
[Test]
public void WithTypeAlias()
{
NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser));
IApplicationContext ctx = new XmlApplicationContext(
ReadOnlyXmlTestResource.GetFilePath("ChannelFactoryObjectDefinitionParserTests.WithTypeAlias.xml", this.GetType()));
Assert.IsTrue(ctx.ContainsObjectDefinition("channel"));
RootObjectDefinition rod = ((IObjectDefinitionRegistry)ctx).GetObjectDefinition("channel") as RootObjectDefinition;
Assert.IsNotNull(rod);
Assert.IsFalse(rod.HasObjectType);
Assert.AreEqual("Spring.ServiceModel.ChannelFactoryObject<IContract>, Spring.Services", rod.ObjectTypeName);
Assert.AreEqual(1, rod.ConstructorArgumentValues.NamedArgumentValues.Count);
Assert.AreEqual("ecn", rod.ConstructorArgumentValues.GetNamedArgumentValue("endpointConfigurationName").Value);
ChannelFactoryObject<IContract> cfo = ctx.GetObject("&channel") as ChannelFactoryObject<IContract>;
Assert.IsNotNull(cfo);
Assert.AreEqual(typeof(IContract), cfo.ObjectType);
IContract contract = ctx.GetObject("channel") as IContract;
Assert.IsNotNull(contract);
}
#region Test classes
[ServiceContract(Namespace = "http://Spring.Services.Tests")]
public interface IContract
{
[OperationContract(Name = "MySomeMethod")]
string SomeMethod(int param);
}
#endregion
}
}
#endif

View File

@@ -0,0 +1,49 @@
#if NET_3_0
#region License
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using Spring.Objects.Factory.Xml;
using NUnit.Framework;
#endregion
namespace Spring.ServiceModel.Config
{
/// <summary>
/// Unit tests for the <see cref="WcfNamespaceParser"/> class.
/// </summary>
/// <author>Bruno Baia</author>
[TestFixture]
public class WcfNamespaceParserTests
{
[Test]
public void Registered()
{
NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser));
INamespaceParser namespaceParser = NamespaceParserRegistry.GetParser("http://www.springframework.net/wcf");
Assert.IsNotNull(namespaceParser);
Assert.IsTrue(namespaceParser is WcfNamespaceParser);
}
}
}
#endif

View File

@@ -30,7 +30,7 @@
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE;DEBUG;NET_2_0;NET_3_0</DefineConstants>
<DefineConstants>TRACE;DEBUG;NET_2_0</DefineConstants>
<DocumentationFile>
</DocumentationFile>
<DebugSymbols>true</DebugSymbols>
@@ -90,7 +90,6 @@
</Reference>
<Reference Include="System.EnterpriseServices" />
<Reference Include="System.Runtime.Remoting" />
<Reference Include="System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
<Reference Include="System.Web.Services" />
<Reference Include="System.Xml">
<Name>System.XML</Name>
@@ -102,7 +101,6 @@
</Compile>
<Compile Include="EnterpriseServices\ExportedServicedComponentSample.cs" />
<Compile Include="EnterpriseServices\ServicedComponentExporterTests.cs" />
<Compile Include="ServiceModel\SpringServiceHostTests.cs" />
<Compile Include="Remoting\BaseRemotingTestFixture.cs" />
<Compile Include="Remoting\CaoExporterTests.cs">
<SubType>Code</SubType>

View File

@@ -111,6 +111,8 @@
<Compile Include="EnterpriseServices\ExeConfigurationSystemTests.cs" />
<Compile Include="EnterpriseServices\ExportedServicedComponentSample.cs" />
<Compile Include="EnterpriseServices\ServicedComponentExporterTests.cs" />
<Compile Include="ServiceModel\Config\ChannelFactoryObjectDefinitionParserTests.cs" />
<Compile Include="ServiceModel\Config\WcfNamespaceParserTests.cs" />
<Compile Include="ServiceModel\SpringServiceHostTests.cs" />
<Compile Include="ServicesCompilerOptionsTests.cs" />
<Compile Include="Remoting\BaseRemotingTestFixture.cs" />
@@ -209,6 +211,10 @@
<Content Include="ServiceComponentExporterTests.TestServicedComponents.Services.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="ServiceModel\Config\ChannelFactoryObjectDefinitionParserTests.WithTypeAlias.xml" />
<EmbeddedResource Include="ServiceModel\Config\ChannelFactoryObjectDefinitionParserTests.WithoutId.xml" />
<EmbeddedResource Include="ServiceModel\Config\ChannelFactoryObjectDefinitionParserTests.CustomProperties.xml" />
<EmbeddedResource Include="ServiceModel\Config\ChannelFactoryObjectDefinitionParserTests.BasicConfig.xml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>

View File

@@ -46,5 +46,13 @@ limitations under the License.
</channels>
</application>
</system.runtime.remoting>
<system.serviceModel>
<client>
<endpoint name="ecn" address="http://localhost/Spring.Services.Tests/ecn.svc" binding="basicHttpBinding" contract="Spring.ServiceModel.Config.ChannelFactoryObjectDefinitionParserTests+IContract"/>
</client>
</system.serviceModel>
</configuration>