Add support for XmlArrayAttribute to WebServiceProxyFactory [SPRNET-988]

This commit is contained in:
bbaia
2008-08-02 15:59:37 +00:00
parent 0ee59eaddf
commit 5ac6e4403c
5 changed files with 193 additions and 7 deletions

View File

@@ -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);

View File

@@ -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)]

View File

@@ -26,6 +26,25 @@
</s:sequence>
</s:complexType>
</s:element>
<s:element name="SayHelloArray">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="name" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="SayHelloArrayResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="out" type="tns:ArrayOfString" />
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="ArrayOfString">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="string" nillable="true" type="s:string" />
</s:sequence>
</s:complexType>
<s:element name="LogHelloWorld">
<s:complexType />
</s:element>
@@ -53,6 +72,12 @@
<wsdl:message name="SayHelloSoapOut">
<wsdl:part name="parameters" element="tns:SayHelloResponse" />
</wsdl:message>
<wsdl:message name="SayHelloArraySoapIn">
<wsdl:part name="parameters" element="tns:SayHelloArray" />
</wsdl:message>
<wsdl:message name="SayHelloArraySoapOut">
<wsdl:part name="parameters" element="tns:SayHelloArrayResponse" />
</wsdl:message>
<wsdl:message name="LogHelloWorldSoapIn">
<wsdl:part name="parameters" element="tns:LogHelloWorld" />
</wsdl:message>
@@ -71,6 +96,10 @@
<wsdl:input message="tns:SayHelloSoapIn" />
<wsdl:output message="tns:SayHelloSoapOut" />
</wsdl:operation>
<wsdl:operation name="SayHelloArray">
<wsdl:input message="tns:SayHelloArraySoapIn" />
<wsdl:output message="tns:SayHelloArraySoapOut" />
</wsdl:operation>
<wsdl:operation name="LogHelloWorld">
<wsdl:input message="tns:LogHelloWorldSoapIn" />
</wsdl:operation>
@@ -99,6 +128,15 @@
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="SayHelloArray">
<soap:operation soapAction="http://www.springframwework.net/SayHelloArray" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="LogHelloWorld">
<soap:operation soapAction="http://www.springframwework.net/LogHelloWorld" style="document" />
<wsdl:input>
@@ -135,6 +173,15 @@
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="SayHelloArray">
<soap12:operation soapAction="http://www.springframwework.net/SayHelloArray" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="LogHelloWorld">
<soap12:operation soapAction="http://www.springframwework.net/LogHelloWorld" style="document" />
<wsdl:input>
@@ -153,10 +200,10 @@
</wsdl:binding>
<wsdl:service name="HelloWorldService">
<wsdl:port name="HelloWorldServiceSoap" binding="tns:HelloWorldServiceSoap">
<soap:address location="http://localhost/HelloWorld/Service.asmx" />
<soap:address location="http://localhost/HelloWebService.asmx" />
</wsdl:port>
<wsdl:port name="HelloWorldServiceSoap12" binding="tns:HelloWorldServiceSoap12">
<soap12:address location="http://localhost/HelloWorld/Service.asmx" />
<soap12:address location="http://localhost/HelloWebService.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

View File

@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://www.springframwework.net" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://www.springframwework.net" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types />
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://www.springframwework.net">
<s:complexType name="ArrayOfString">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="string" nillable="true" type="s:string" />
</s:sequence>
</s:complexType>
</s:schema>
</wsdl:types>
<wsdl:message name="SayHelloWorldSoapIn" />
<wsdl:message name="SayHelloWorldSoapOut">
<wsdl:part name="SayHelloWorldResult" type="s:string" />
@@ -11,6 +19,12 @@
<wsdl:message name="SayHelloSoapOut">
<wsdl:part name="out" type="s:string" />
</wsdl:message>
<wsdl:message name="SayHelloArraySoapIn">
<wsdl:part name="name" type="s:string" />
</wsdl:message>
<wsdl:message name="SayHelloArraySoapOut">
<wsdl:part name="out" type="tns:ArrayOfString" />
</wsdl:message>
<wsdl:message name="LogHelloWorldSoapIn" />
<wsdl:message name="MyLogHelloSoapIn">
<wsdl:part name="name" type="s:string" />
@@ -25,6 +39,10 @@
<wsdl:input message="tns:SayHelloSoapIn" />
<wsdl:output message="tns:SayHelloSoapOut" />
</wsdl:operation>
<wsdl:operation name="SayHelloArray">
<wsdl:input message="tns:SayHelloArraySoapIn" />
<wsdl:output message="tns:SayHelloArraySoapOut" />
</wsdl:operation>
<wsdl:operation name="LogHelloWorld">
<wsdl:input message="tns:LogHelloWorldSoapIn" />
</wsdl:operation>
@@ -53,6 +71,15 @@
<soap:body use="literal" namespace="http://www.springframwework.net" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="SayHelloArray">
<soap:operation soapAction="http://www.springframwework.net/SayHelloArray" style="rpc" />
<wsdl:input>
<soap:body use="literal" namespace="http://www.springframwework.net" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" namespace="http://www.springframwework.net" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="LogHelloWorld">
<soap:operation soapAction="http://www.springframwework.net/LogHelloWorld" style="rpc" />
<wsdl:input>
@@ -89,6 +116,15 @@
<soap12:body use="literal" namespace="http://www.springframwework.net" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="SayHelloArray">
<soap12:operation soapAction="http://www.springframwework.net/SayHelloArray" style="rpc" />
<wsdl:input>
<soap12:body use="literal" namespace="http://www.springframwework.net" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" namespace="http://www.springframwework.net" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="LogHelloWorld">
<soap12:operation soapAction="http://www.springframwework.net/LogHelloWorld" style="rpc" />
<wsdl:input>
@@ -107,10 +143,10 @@
</wsdl:binding>
<wsdl:service name="HelloWorldService">
<wsdl:port name="HelloWorldServiceSoap" binding="tns:HelloWorldServiceSoap">
<soap:address location="http://localhost/HelloWorld/Service.asmx" />
<soap:address location="http://localhost:2375/HelloWebService.asmx" />
</wsdl:port>
<wsdl:port name="HelloWorldServiceSoap12" binding="tns:HelloWorldServiceSoap12">
<soap12:address location="http://localhost/HelloWorld/Service.asmx" />
<soap12:address location="http://localhost:2375/HelloWebService.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

View File

@@ -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()
{
}