// Invoke the operation for the requested service public object Invoke(string service, string operation, DataParameterCollection dpc, int timeout) { // Create an instance of the service object proxy object o = _WsdlAssembly.CreateInstance(_Namespace + "." + service, false); if (o == null) throw new Exception(string.Format("Unable to create instance of service '{0}'.", service)); // Get information about the method MethodInfo mi = o.GetType().GetMethod(operation); if (mi == null) throw new Exception(string.Format("Unable to find operation '{0}' in service '{1}'.", operation, service)); // Go thru the parameters building up an object array with the proper parameters ParameterInfo[] pis = mi.GetParameters(); object[] args = new object[pis.Length]; int ai=0; foreach (ParameterInfo pi in pis) { BaseDataParameter dp = dpc[pi.Name] as BaseDataParameter; if (dp == null) // retry with '@' in front! dp = dpc["@"+pi.Name] as BaseDataParameter; if (dp == null || dp.Value == null) args[ai] = null; else if (pi.ParameterType == dp.Value.GetType()) args[ai] = dp.Value; else // we need to do conversion args[ai] = Convert.ChangeType(dp.Value, pi.ParameterType); ai++; } SoapHttpClientProtocol so = o as SoapHttpClientProtocol; if (so != null && timeout != 0) so.Timeout = timeout; return mi.Invoke(o, args); }