P
phancey
I am trying to invoke a web service method dynamically. I have created
a generic function that takes a method name, string of parameters and
calls the web method using System.Reflection:
MethodInfo mi = proxyInstance.GetType().GetMethod(methodName);
object[] paramsArray = (object[])methodParams.ToArray(typeof(object));
object result = mi.Invoke(proxyInstance, paramsArray);
where methodParams is an array of parameters where the value stripped
from the string has been converted into the relevant system.type using:
methodParams = Convert.ChangeType(methodParams,
(mi.GetParameters()).ParameterType);
This works fine unless the web method uses reference parameters.
Reference parameters themselves are not a problem if I didn't have to
use the Convert.ChangeType function. Convert.ChangeType does not work
with type System.Int32&.
Ref strings are fine because I can just avoid using the function
altogether but is there a way I can get the base type of a ByRef
parameter? I had a look at the structure of ParameterType but couldn't
find anywhere where System.Int32& could be interpreted as System.Int32
I can use this:
if (pi.ParameterType == System.Type.GetType("System.Int32&"))
paramValue = Convert.ChangeType(paramValue,
System.Type.GetType("System.Int32") );
but this requires me to code for each specific ref type. Is there a
simple property that allows me to get the right type?
thanks
Phil
a generic function that takes a method name, string of parameters and
calls the web method using System.Reflection:
MethodInfo mi = proxyInstance.GetType().GetMethod(methodName);
object[] paramsArray = (object[])methodParams.ToArray(typeof(object));
object result = mi.Invoke(proxyInstance, paramsArray);
where methodParams is an array of parameters where the value stripped
from the string has been converted into the relevant system.type using:
methodParams = Convert.ChangeType(methodParams,
(mi.GetParameters()).ParameterType);
This works fine unless the web method uses reference parameters.
Reference parameters themselves are not a problem if I didn't have to
use the Convert.ChangeType function. Convert.ChangeType does not work
with type System.Int32&.
Ref strings are fine because I can just avoid using the function
altogether but is there a way I can get the base type of a ByRef
parameter? I had a look at the structure of ParameterType but couldn't
find anywhere where System.Int32& could be interpreted as System.Int32
I can use this:
if (pi.ParameterType == System.Type.GetType("System.Int32&"))
paramValue = Convert.ChangeType(paramValue,
System.Type.GetType("System.Int32") );
but this requires me to code for each specific ref type. Is there a
simple property that allows me to get the right type?
thanks
Phil