Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Services/Web/Services
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17100
Modified Files:
WebServiceProxyFactory.cs
Log Message:
Refactored Stan D. contribution [SPRNET-606]
Index: WebServiceProxyFactory.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Services/Web/Services/WebServiceProxyFactory.cs,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** WebServiceProxyFactory.cs 29 Nov 2007 13:13:14 -0000 1.27
--- WebServiceProxyFactory.cs 3 Dec 2007 09:07:31 -0000 1.28
***************
*** 570,582 ****
}
#if NET_2_0
! protected override void ApplyMethodReturnTypeAttributes(
! MethodBuilder methodBuilder, MethodInfo targetMethod)
{
! base.ApplyMethodReturnTypeAttributes(methodBuilder, targetMethod);
if (operation.Messages.Output != null)
{
! if (targetMethod.ReturnType != typeof(void))
{
if (outputMembersMapping.Count > 0)
--- 570,610 ----
}
+ protected override IList GetTypeAttributes(Type type)
+ {
+ IList attrs = base.GetTypeAttributes(type);
+
+ // Add the WebServiceBindingAttribute
+ attrs.Add(CreateWebServiceBindingAttribute(this.wsBinding));
+
+ return attrs;
+ }
+
+ protected override IList GetMethodAttributes(MethodInfo method)
+ {
+ IList attrs = base.GetMethodAttributes(method);
+
+ // Add the SoapHeaderAttribute (Only SoapHeaders with Direction=SoapHeaderDirection.In are supported)
+ foreach (SoapHeaderBinding soapHeaderBinding in operationBinding.Input.Extensions.FindAll(typeof(SoapHeaderBinding)))
+ {
+ soapHeaderFieldNames.Add(soapHeaderBinding.Part);
+ attrs.Add(CreateSoapHeaderAttribute(soapHeaderBinding.Part, SoapHeaderDirection.In));
+ }
+
+ // Add the SoapMethodAttribute
+ attrs.Add(CreateSoapMethodAttribute(
+ operation, operationBinding, soapOperationBinding, inputMembersMapping, outputMembersMapping));
+
+ return attrs;
+ }
+
#if NET_2_0
! protected override IList GetMethodReturnTypeAttributes(MethodInfo method)
{
! IList attrs = base.GetMethodReturnTypeAttributes(method);
+ // Add the XmlElementAttribute if needed
if (operation.Messages.Output != null)
{
! if (method.ReturnType != typeof(void))
{
if (outputMembersMapping.Count > 0)
***************
*** 587,594 ****
if (useMemberName || useNamespace)
{
! ParameterBuilder parameterBuilder = methodBuilder.DefineParameter(0, ParameterAttributes.Retval, null);
!
! CustomAttributeBuilderBuilder cabb =
! new CustomAttributeBuilderBuilder(typeof(XmlElementAttribute));
if (useMemberName)
{
--- 615,620 ----
if (useMemberName || useNamespace)
{
! ReflectionUtils.CustomAttributeBuilderBuilder cabb =
! new ReflectionUtils.CustomAttributeBuilderBuilder(typeof(XmlElementAttribute));
if (useMemberName)
{
***************
*** 600,662 ****
}
! parameterBuilder.SetCustomAttribute(cabb.Build());
}
}
}
}
}
#endif
/*
! protected override void ApplyMethodParameterAttributes(MethodBuilder methodBuilder, MethodInfo targetMethod)
{
! base.ApplyMethodParameterAttributes(methodBuilder, targetMethod);
! foreach (ParameterInfo paramInfo in targetMethod.GetParameters())
{
! XmlMemberMapping inMemberMapping = inputMembersMapping[paramInfo.Position];
! if (inMemberMapping.Namespace != inputMembersMapping.Namespace)
! {
! ParameterBuilder parameterBuilder = methodBuilder.DefineParameter((paramInfo.Position + 1), paramInfo.Attributes, paramInfo.Name);
!
! CustomAttributeBuilderBuilder cabb =
! new CustomAttributeBuilderBuilder(typeof(XmlElementAttribute));
! cabb.AddPropertyValue("Namespace", inMemberMapping.Namespace);
!
! parameterBuilder.SetCustomAttribute(cabb.Build());
! }
! }
! }
! */
!
! protected override IList GetTypeAttributes(Type type)
! {
! IList attrs = base.GetTypeAttributes(type);
!
! attrs.Add(CreateWebServiceBindingAttribute(this.wsBinding));
!
! return attrs;
! }
!
! protected override IList GetMethodAttributes(MethodInfo method)
! {
! IList attrs = base.GetMethodAttributes(method);
! // SoapHeaderAttribute (Only SoapHeaders with Direction=SoapHeaderDirection.In are supported)
! foreach (SoapHeaderBinding soapHeaderBinding in operationBinding.Input.Extensions.FindAll(typeof(SoapHeaderBinding)))
! {
! soapHeaderFieldNames.Add(soapHeaderBinding.Part);
! attrs.Add(CreateSoapHeaderAttribute(soapHeaderBinding.Part, SoapHeaderDirection.In));
}
- // SoapMethodAttribute
- attrs.Add(CreateSoapMethodAttribute(
- operation, operationBinding, soapOperationBinding, inputMembersMapping, outputMembersMapping));
-
return attrs;
}
#endregion
! #region Private Helper Methods
private void Initialize(DiscoveryClientDocumentCollection wsDocuments, string bindingName)
--- 626,661 ----
}
! attrs.Add(cabb.Build());
}
}
}
}
+
+ return attrs;
}
#endif
/*
! protected override IList GetMethodParameterAttributes(MethodInfo method, ParameterInfo paramInfo)
{
! IList attrs = base.GetMethodParameterAttributes(method, paramInfo);
! // Add the XmlElementAttribute if needed
! XmlMemberMapping inMemberMapping = inputMembersMapping[paramInfo.Position];
! if (inMemberMapping.Namespace != inputMembersMapping.Namespace)
{
! CustomAttributeBuilderBuilder cabb =
! new CustomAttributeBuilderBuilder(typeof(XmlElementAttribute));
! cabb.AddPropertyValue("Namespace", inMemberMapping.Namespace);
! attrs.Add(cabb.Build());
}
return attrs;
}
+ */
#endregion
! #region Private Methods
private void Initialize(DiscoveryClientDocumentCollection wsDocuments, string bindingName)
***************
*** 857,862 ****
private CustomAttributeBuilder CreateWebServiceBindingAttribute(Binding wsBinding)
{
! CustomAttributeBuilderBuilder cabb =
! new CustomAttributeBuilderBuilder(typeof(WebServiceBindingAttribute));
cabb.AddContructorArgument(this.wsBinding.Name);
--- 856,861 ----
private CustomAttributeBuilder CreateWebServiceBindingAttribute(Binding wsBinding)
{
! ReflectionUtils.CustomAttributeBuilderBuilder cabb =
! new ReflectionUtils.CustomAttributeBuilderBuilder(typeof(WebServiceBindingAttribute));
cabb.AddContructorArgument(this.wsBinding.Name);
***************
*** 880,885 ****
string memberName, SoapHeaderDirection direction)
{
! CustomAttributeBuilderBuilder cabb =
! new CustomAttributeBuilderBuilder(typeof(SoapHeaderAttribute));
cabb.AddContructorArgument(memberName);
--- 879,884 ----
string memberName, SoapHeaderDirection direction)
{
! ReflectionUtils.CustomAttributeBuilderBuilder cabb =
! new ReflectionUtils.CustomAttributeBuilderBuilder(typeof(SoapHeaderAttribute));
cabb.AddContructorArgument(memberName);
***************
*** 897,901 ****
XmlMembersMapping inputMembersMapping, XmlMembersMapping outputMembersMapping)
{
! CustomAttributeBuilderBuilder cabb;
#if !NET_2_0
--- 896,900 ----
XmlMembersMapping inputMembersMapping, XmlMembersMapping outputMembersMapping)
{
! ReflectionUtils.CustomAttributeBuilderBuilder cabb;
#if !NET_2_0
***************
*** 910,918 ****
if (soapOperationBinding.Style == SoapBindingStyle.Rpc)
{
! cabb = new CustomAttributeBuilderBuilder(typeof(SoapRpcMethodAttribute));
}
else
{
! cabb = new CustomAttributeBuilderBuilder(typeof(SoapDocumentMethodAttribute));
cabb.AddPropertyValue("ParameterStyle", SoapParameterStyle.Wrapped);
}
--- 909,917 ----
if (soapOperationBinding.Style == SoapBindingStyle.Rpc)
{
! cabb = new ReflectionUtils.CustomAttributeBuilderBuilder(typeof(SoapRpcMethodAttribute));
}
else
{
! cabb = new ReflectionUtils.CustomAttributeBuilderBuilder(typeof(SoapDocumentMethodAttribute));
cabb.AddPropertyValue("ParameterStyle", SoapParameterStyle.Wrapped);
}
***************
*** 1115,1242 ****
#endregion
-
- #region CustomAttributeBuilderBuilder inner class implementation
-
- /// <summary>
- /// Creates a <see cref=" CustomAttributeBuilder"/>.
- /// </summary>
- private sealed class CustomAttributeBuilderBuilder
- {
- #region Fields
-
- private Type type;
- private ArrayList constructorArgs;
- private ArrayList namedProperties;
- private ArrayList propertyValues;
-
- #endregion
-
- #region Constructor(s) / Destructor
-
- /// <summary>
- /// Creates a new instance of the
- /// <see cref="CustomAttributeBuilderBuilder"/> class.
- /// </summary>
- /// <param name="attributeType">The custom attribute type.</param>
- public CustomAttributeBuilderBuilder(Type attributeType)
- :
- this(attributeType, ObjectUtils.EmptyObjects)
- {
- }
-
- /// <summary>
- /// Creates a new instance of the
- /// <see cref="CustomAttributeBuilderBuilder"/> class.
- /// </summary>
- /// <param name="attributeType">The custom attribute type.</param>
- /// <param name="constructorArgs">The custom attribute constructor arguments.</param>
- public CustomAttributeBuilderBuilder(Type attributeType, ICollection constructorArgs)
- {
- AssertUtils.ArgumentNotNull(attributeType, "attributeType");
- if (!typeof(Attribute).IsAssignableFrom(attributeType))
- {
- throw new ArgumentException(
- string.Format("[{0}] does not derive from the [System.Attribute] class.",
- attributeType.FullName));
- }
- this.type = attributeType;
- this.constructorArgs = new ArrayList(constructorArgs);
- this.namedProperties = new ArrayList();
- this.propertyValues = new ArrayList();
- }
-
- #endregion
-
- #region Public Methods
-
- /// <summary>
- /// Adds the specified object to the constructor argument list
- /// used to create the custom attribute.
- /// </summary>
- /// <param name="value">The property value.</param>
- public void AddContructorArgument(object value)
- {
- this.constructorArgs.Add(value);
- }
-
- /// <summary>
- /// Adds the specified collection to the constructor argument list
- /// used to create the custom attribute.
- /// </summary>
- /// <param name="values">An array of argument values.</param>
- public void AddContructorArgument(ICollection values)
- {
- this.constructorArgs.AddRange(values);
- }
-
- /// <summary>
- /// Adds a property value to the custom attribute.
- /// </summary>
- /// <param name="name">The property name.</param>
- /// <param name="value">The property value.</param>
- public void AddPropertyValue(string name, object value)
- {
- PropertyInfo propertyInfo = this.type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public);
- if (propertyInfo == null)
- {
- throw new ArgumentException(
- String.Format("The property '{0}' does no exist in the attribute '{1}'.", name, this.type));
- }
-
- this.namedProperties.Add(propertyInfo);
- this.propertyValues.Add(value);
- }
-
- /// <summary>
- /// Creates the <see cref="CustomAttributeBuilderBuilder"/>.
- /// </summary>
- /// <returns>The created <see cref="CustomAttributeBuilderBuilder"/>.</returns>
- public CustomAttributeBuilder Build()
- {
- object[] caArray = (object[])this.constructorArgs.ToArray(typeof(object));
- ConstructorInfo ci = this.type.GetConstructor(ReflectionUtils.GetTypes(caArray));
- if (ci == null && caArray.Length == 0)
- {
- ci = this.type.GetConstructors()[0];
- caArray = ReflectionUtils.GetDefaultValues(ReflectionUtils.GetParameterTypes(ci.GetParameters()));
- }
-
- if (namedProperties.Count > 0)
- {
- PropertyInfo[] npArray = (PropertyInfo[])this.namedProperties.ToArray(typeof(PropertyInfo));
- object[] pvArray = (object[])this.propertyValues.ToArray(typeof(object));
- return new CustomAttributeBuilder(ci, caArray, npArray, pvArray);
- }
- else
- {
- return new CustomAttributeBuilder(ci, caArray);
- }
-
- }
-
- #endregion
- }
-
- #endregion
}
--- 1114,1117 ----
|