public XmlRpcClient(XmlRpcClientConfig config) { this.config = config; }
public object Invoke(MethodInfo mi, params object[] parameters) { try { XmlRpcClientConfig config = new XmlRpcClientConfig(this.WebAddress); config.ProxyServer = this.ProxyServer; config.ProxyPort = this.ProxyPort; if (this.Credentials != null) { config.Password = this.Credentials.Password; config.UserName = this.Credentials.UserName; } string rpcMethodName = GetRpcMethodName(mi); XmlRpcClient client = new XmlRpcClient(config); Type type = client.GetType(); object[] args = new object[4]; args[0] = rpcMethodName; args[1] = parameters; args[2] = Attachments; this.ResponseParts = new HashSet <Part>(); args[3] = this.ResponseParts; System.Reflection.MethodInfo executeMethod = type.GetMethod("Execute"); if (mi.ReturnType.Name != "Void") { executeMethod = executeMethod.MakeGenericMethod(mi.ReturnType); } else { Type[] types = { typeof(string) }; executeMethod = executeMethod.MakeGenericMethod(types); } object ObjToReturn = executeMethod.Invoke(client, args); this.ResponseParts = (HashSet <Part>)args[3]; return(ObjToReturn); } catch (TargetInvocationException ex) { XmlRpcTraceEventLogListener.WriteError(ex); Exception e = ex.GetBaseException(); if (e is SocketException) { MessageBox.Show("Existe un error de comunicación con el publicador.\r\nPuede que el sistema este inestable debido a esta situación.\r\nCierre la aplicación y vuelva a intentar la operación.\r\nDetalle: " + e.Message, "Error de comunicación", MessageBoxButtons.OK, MessageBoxIcon.Error); XmlRpcTraceEventLogListener.WriteError(e); throw e; } else { throw e; } } catch (XmlRpcException webex) { XmlRpcTraceEventLogListener.WriteError(webex); throw webex; } catch (WebException webex) { XmlRpcTraceEventLogListener.WriteError(webex); throw webex; } catch (NullReferenceException webex) { XmlRpcTraceEventLogListener.WriteError(webex); throw webex; } finally { this.Attachments.Clear(); } }