wbrussell / xmlrpcnet

Automatically exported from code.google.com/p/xmlrpcnet
0 stars 0 forks source link

InvalidCastException when returning null from a string[] methhod. #105

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Declare a an interface with a method using string[] datatype:

[XmlRpcMethod]
string[] TestCase();

2. Implement the method in the server, and make it return null:

[XmlRpcService(UseIndentation = false)]
class TestServices : XmlRpcListenerService, IPosServices
{
    public string[] TestCase()
    {
        return null;
    }
}

3. Call the method from the client

string[] returnValue = proxy.TestCase();

What is the expected output? What do you see instead?

I would expect the call to succeed, and returnValue to be null. However, if 
UseStringTag=false in the server a System.InvalidCastException is thrown:

Unable to cast object of type 'System.String' to type 'System.String[]',

Is UseStringTag=true, then a CookComputnig.XmlRpc.XmlRpcTypeMismatchException 
is thrown:

response contains string value where array expected [response]

   at CookComputing.XmlRpc.XmlRpcSerializer.ParseString(XmlNode node, Type ValueType, ParseStack parseStack, MappingAction mappingAction)
   at CookComputing.XmlRpc.XmlRpcSerializer.ParseValue(XmlNode node, Type ValueType, ParseStack parseStack, MappingAction mappingAction, Type& ParsedType, Type& ParsedArrayType)
   at CookComputing.XmlRpc.XmlRpcSerializer.ParseValue(XmlNode node, Type ValueType, ParseStack parseStack, MappingAction mappingAction)
   at CookComputing.XmlRpc.XmlRpcSerializer.DeserializeResponse(XmlDocument xdoc, Type returnType)
   at CookComputing.XmlRpc.XmlRpcSerializer.DeserializeResponse(Stream stm, Type svcType)
   at CookComputing.XmlRpc.XmlRpcClientProtocol.ReadResponse(XmlRpcRequest req, WebResponse webResp, Stream respStm, Type returnType)
   at CookComputing.XmlRpc.XmlRpcClientProtocol.Invoke(Object clientObj, MethodInfo mi, Object[] parameters)
   at CookComputing.XmlRpc.XmlRpcClientProtocol.Invoke(MethodInfo mi, Object[] Parameters)
   ...

When UseStringTag=false, communication trace is as follows:

Request: <?xml 
version="1.0"?><methodCall><methodName>TestCase</methodName><params/></methodCal
l>
Response: <?xml version="1.0"?><methodResponse><params><param><value 
/></param></params></methodResponse>

When UseStringTag=true, communication trace is:

Request: <?xml 
version="1.0"?><methodCall><methodName>TestCase</methodName><params/></methodCal
l>
Response: <?xml version="1.0"?><methodResponse><params><param><value><string 
/></value></param></params></methodResponse>

I guess NULL return value is treated as a string by default?

Original issue reported on code.google.com by airadier on 26 Oct 2012 at 12:03