From 5ac6e4403c72b9594370672fb86de419b82f6498 Mon Sep 17 00:00:00 2001 From: bbaia Date: Sat, 2 Aug 2008 15:59:37 +0000 Subject: [PATCH] Add support for XmlArrayAttribute to WebServiceProxyFactory [SPRNET-988] --- .../Web/Services/WebServiceProxyFactory.cs | 11 ++- .../Data/Spring/Web/Services/Service.cs.fyi | 7 ++ .../Spring/Web/Services/document-literal.wsdl | 51 ++++++++++- .../Data/Spring/Web/Services/rpc-literal.wsdl | 42 ++++++++- .../Services/WebServiceProxyFactoryTests.cs | 89 +++++++++++++++++++ 5 files changed, 193 insertions(+), 7 deletions(-) diff --git a/src/Spring/Spring.Services/Web/Services/WebServiceProxyFactory.cs b/src/Spring/Spring.Services/Web/Services/WebServiceProxyFactory.cs index 844ea30e..84b92ac2 100644 --- a/src/Spring/Spring.Services/Web/Services/WebServiceProxyFactory.cs +++ b/src/Spring/Spring.Services/Web/Services/WebServiceProxyFactory.cs @@ -626,8 +626,15 @@ namespace Spring.Web.Services bool useNamespace = outMemberMapping.Namespace != outputMembersMapping.Namespace; if (useMemberName || useNamespace) { - ReflectionUtils.CustomAttributeBuilderBuilder cabb = - new ReflectionUtils.CustomAttributeBuilderBuilder(typeof(XmlElementAttribute)); + ReflectionUtils.CustomAttributeBuilderBuilder cabb; + if (outMemberMapping.TypeName.StartsWith ("ArrayOf", StringComparison.Ordinal)) + { + cabb = new ReflectionUtils.CustomAttributeBuilderBuilder(typeof(XmlArrayAttribute)); + } + else + { + cabb = new ReflectionUtils.CustomAttributeBuilderBuilder(typeof(XmlElementAttribute)); + } if (useMemberName) { cabb.AddPropertyValue("ElementName", outMemberMapping.MemberName); diff --git a/test/Spring/Spring.Services.Tests/Data/Spring/Web/Services/Service.cs.fyi b/test/Spring/Spring.Services.Tests/Data/Spring/Web/Services/Service.cs.fyi index 9416791d..02b8f9fc 100644 --- a/test/Spring/Spring.Services.Tests/Data/Spring/Web/Services/Service.cs.fyi +++ b/test/Spring/Spring.Services.Tests/Data/Spring/Web/Services/Service.cs.fyi @@ -31,6 +31,13 @@ public class HelloWorldService : System.Web.Services.WebService { return String.Format("Hello {0} !", name); } + + [WebMethod] + [return: XmlArray("out")] + public string[] SayHelloArray(string name) + { + return new string[] { "Hello ", name, " !" }; + } [WebMethod] [SoapDocumentMethod(OneWay = true)] diff --git a/test/Spring/Spring.Services.Tests/Data/Spring/Web/Services/document-literal.wsdl b/test/Spring/Spring.Services.Tests/Data/Spring/Web/Services/document-literal.wsdl index cdf8055a..859f280a 100644 --- a/test/Spring/Spring.Services.Tests/Data/Spring/Web/Services/document-literal.wsdl +++ b/test/Spring/Spring.Services.Tests/Data/Spring/Web/Services/document-literal.wsdl @@ -26,6 +26,25 @@ + + + + + + + + + + + + + + + + + + + @@ -53,6 +72,12 @@ + + + + + + @@ -71,6 +96,10 @@ + + + + @@ -99,6 +128,15 @@ + + + + + + + + + @@ -135,6 +173,15 @@ + + + + + + + + + @@ -153,10 +200,10 @@ - + - + \ No newline at end of file diff --git a/test/Spring/Spring.Services.Tests/Data/Spring/Web/Services/rpc-literal.wsdl b/test/Spring/Spring.Services.Tests/Data/Spring/Web/Services/rpc-literal.wsdl index ce4fe596..6fdab5a4 100644 --- a/test/Spring/Spring.Services.Tests/Data/Spring/Web/Services/rpc-literal.wsdl +++ b/test/Spring/Spring.Services.Tests/Data/Spring/Web/Services/rpc-literal.wsdl @@ -1,6 +1,14 @@  - + + + + + + + + + @@ -11,6 +19,12 @@ + + + + + + @@ -25,6 +39,10 @@ + + + + @@ -53,6 +71,15 @@ + + + + + + + + + @@ -89,6 +116,15 @@ + + + + + + + + + @@ -107,10 +143,10 @@ - + - + \ No newline at end of file diff --git a/test/Spring/Spring.Services.Tests/Web/Services/WebServiceProxyFactoryTests.cs b/test/Spring/Spring.Services.Tests/Web/Services/WebServiceProxyFactoryTests.cs index 547bf639..80b31e9e 100644 --- a/test/Spring/Spring.Services.Tests/Web/Services/WebServiceProxyFactoryTests.cs +++ b/test/Spring/Spring.Services.Tests/Web/Services/WebServiceProxyFactoryTests.cs @@ -215,6 +215,48 @@ namespace Spring.Web.Services ObjectUtils.InstantiateType(proxyType); } + [Test] + public void DocumentLiteralWithNamedOutArrayParameter() + { + WebServiceProxyFactory wspf = new WebServiceProxyFactory(); + wspf.ServiceUri = new AssemblyResource("assembly://Spring.Services.Tests/Spring.Data.Spring.Web.Services/document-literal.wsdl"); + wspf.ServiceInterface = typeof(IHelloWorld); + wspf.AfterPropertiesSet(); + + object proxy = wspf.GetObject(); + Assert.IsNotNull(proxy); + + Type proxyType = proxy.GetType(); + Assert.IsTrue(proxy is IHelloWorld); + Assert.IsTrue(proxy is SoapHttpClientProtocol); + + MethodInfo sayHelloArrayMethod = proxyType.GetMethod("SayHelloArray"); + Assert.IsNotNull(sayHelloArrayMethod); + + object[] sdmaAttrs = sayHelloArrayMethod.GetCustomAttributes(typeof(SoapDocumentMethodAttribute), false); + Assert.IsTrue(sdmaAttrs.Length > 0); + + SoapDocumentMethodAttribute sdma = (SoapDocumentMethodAttribute)sdmaAttrs[0]; + Assert.AreEqual("http://www.springframwework.net/SayHelloArray", sdma.Action); + Assert.AreEqual(SoapParameterStyle.Wrapped, sdma.ParameterStyle); + Assert.AreEqual(string.Empty, sdma.Binding); + Assert.AreEqual(false, sdma.OneWay); + Assert.AreEqual(string.Empty, sdma.RequestElementName); + Assert.AreEqual("http://www.springframwework.net", sdma.RequestNamespace); + Assert.AreEqual(string.Empty, sdma.ResponseElementName); + Assert.AreEqual("http://www.springframwework.net", sdma.ResponseNamespace); + Assert.AreEqual(SoapBindingUse.Literal, sdma.Use); + + object[] xaAttrs = sayHelloArrayMethod.ReturnTypeCustomAttributes.GetCustomAttributes(typeof(XmlArrayAttribute), false); + Assert.IsTrue(xaAttrs.Length > 0); + + XmlArrayAttribute xaa = (XmlArrayAttribute)xaAttrs[0]; + Assert.AreEqual("out", xaa.ElementName); + + // Try to instantiate the proxy type + ObjectUtils.InstantiateType(proxyType); + } + [Test] public void RpcLiteralWithNamedOutParameter() { @@ -256,6 +298,47 @@ namespace Spring.Web.Services ObjectUtils.InstantiateType(proxyType); } + [Test] + public void RpcLiteralWithNamedOutArrayParameter() + { + WebServiceProxyFactory wspf = new WebServiceProxyFactory(); + wspf.ServiceUri = new AssemblyResource("assembly://Spring.Services.Tests/Spring.Data.Spring.Web.Services/rpc-literal.wsdl"); + wspf.ServiceInterface = typeof(IHelloWorld); + wspf.AfterPropertiesSet(); + + object proxy = wspf.GetObject(); + Assert.IsNotNull(proxy); + + Type proxyType = proxy.GetType(); + Assert.IsTrue(proxy is IHelloWorld); + Assert.IsTrue(proxy is SoapHttpClientProtocol); + + MethodInfo sayHelloArrayMethod = proxyType.GetMethod("SayHelloArray"); + Assert.IsNotNull(sayHelloArrayMethod); + + object[] srmaAttrs = sayHelloArrayMethod.GetCustomAttributes(typeof(SoapRpcMethodAttribute), false); + Assert.IsTrue(srmaAttrs.Length > 0); + + SoapRpcMethodAttribute srma = (SoapRpcMethodAttribute)srmaAttrs[0]; + Assert.AreEqual("http://www.springframwework.net/SayHelloArray", srma.Action); + Assert.AreEqual(string.Empty, srma.Binding); + Assert.AreEqual(false, srma.OneWay); + Assert.AreEqual(string.Empty, srma.RequestElementName); + Assert.AreEqual("http://www.springframwework.net", srma.RequestNamespace); + Assert.AreEqual(string.Empty, srma.ResponseElementName); + Assert.AreEqual("http://www.springframwework.net", srma.ResponseNamespace); + Assert.AreEqual(SoapBindingUse.Literal, srma.Use); + + object[] xaAttrs = sayHelloArrayMethod.ReturnTypeCustomAttributes.GetCustomAttributes(typeof(XmlArrayAttribute), false); + Assert.IsTrue(xaAttrs.Length > 0); + + XmlArrayAttribute xaa = (XmlArrayAttribute)xaAttrs[0]; + Assert.AreEqual("out", xaa.ElementName); + + // Try to instantiate the proxy type + ObjectUtils.InstantiateType(proxyType); + } + [Test] public void RpcLiteralWithDefaultConfig() { @@ -538,6 +621,7 @@ namespace Spring.Web.Services { string SayHelloWorld(); string SayHello(string name); + string[] SayHelloArray(string name); void LogHelloWorld(); void LogHello(string name); } @@ -566,6 +650,11 @@ namespace Spring.Web.Services return String.Format("Hello {0} !", name); } + public string[] SayHelloArray(string name) + { + return new string[] { "Hello ", name, " !" }; + } + public void LogHelloWorld() { }