/// <summary> /// Call a method and return the XML result. Will throw an exception of type BlogClientException /// if an error occurs. /// </summary> /// <param name="postUrl"></param> /// <param name="methodName"></param> /// <param name="parameters"></param> /// <returns></returns> protected XmlNode CallMethod(string methodName, params XmlRpcValue[] parameters) { string url = _postApiUrl; if (Options.SupportsHttps) { if (url.StartsWith("http://", StringComparison.OrdinalIgnoreCase)) url = "https://" + url.Substring("http://".Length); } try { // create an RpcClient XmlRpcClient xmlRpcClient = new XmlRpcClient(url, ApplicationEnvironment.UserAgent, new HttpRequestFilter(BeforeHttpRequest), _clientOptions.CharacterSet); // call the method XmlRpcMethodResponse response = xmlRpcClient.CallMethod(methodName, parameters); // if success, return the response if (!response.FaultOccurred) { return response.Response; } else // throw error indicating problem { // prepare to throw exception BlogClientException exception; // allow underlying provider to return a more descriptive exception type exception = ExceptionForFault(response.FaultCode, response.FaultString); if (exception == null) // if it couldn't just go generic exception = new BlogClientProviderException(response.FaultCode, response.FaultString); // throw the exception throw exception; } } catch (IOException ex) { throw new BlogClientIOException("calling XML-RPC method " + methodName, ex); } catch (WebException ex) { HttpRequestHelper.LogException(ex); // see if this was a 404 not found switch (ex.Status) { case WebExceptionStatus.ProtocolError: HttpWebResponse response = ex.Response as HttpWebResponse; if (response != null && response.StatusCode == HttpStatusCode.NotFound) throw new BlogClientPostUrlNotFoundException(url, ex.Message); else if (response.StatusCode == HttpStatusCode.Unauthorized) throw new BlogClientAuthenticationException(response.StatusCode.ToString(), ex.Message, ex); else throw new BlogClientHttpErrorException(url, string.Format(CultureInfo.InvariantCulture, "{0} {1}", (int)response.StatusCode, response.StatusDescription), ex); default: throw new BlogClientConnectionErrorException(url, ex.Message); } } catch (XmlRpcClientInvalidResponseException ex) { throw new BlogClientInvalidServerResponseException(methodName, ex.Message, ex.Response); } }
public void ThreadStart() { foreach (string url in _pingUrls) { try { Uri uri = new Uri(url); if (uri.Scheme.ToLower(CultureInfo.InvariantCulture) == "http" || uri.Scheme.ToLower(CultureInfo.InvariantCulture) == "https") { XmlRpcClient client = new XmlRpcClient(url, ApplicationEnvironment.UserAgent); client.CallMethod("weblogUpdates.ping", _blogName, _blogUrl); } } catch (Exception e) { if (ApplicationDiagnostics.VerboseLogging) Trace.Fail("Failure while pinging " + url + ": " + e.ToString()); } } }