//// /// Copyright (c) 2016 Saúl Piña . /// /// This file is part of xmlrpcwsc. /// /// xmlrpcwsc is free software: you can redistribute it and/or modify /// it under the terms of the GNU Lesser General Public License as published by /// the Free Software Foundation, either version 3 of the License, or /// (at your option) any later version. /// /// xmlrpcwsc is distributed in the hope that it will be useful, /// but WITHOUT ANY WARRANTY; without even the implied warranty of /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /// GNU Lesser General Public License for more details. /// /// You should have received a copy of the GNU Lesser General Public License /// along with xmlrpcwsc. If not, see . //// using System; using System.Xml; using System.IO; using System.Text; using System.Collections.Generic; namespace XmlRpc { /// /// XML-RPC client /// public class XmlRpcClient : WebServiceConnection { protected XmlDocument xmlRequest; protected XmlDocument xmlResponse; protected XmlRpcRequest request; protected XmlRpcResponse response; /// /// Gets the xml request /// /// The xml request public XmlDocument GetXmlRequest() { return xmlRequest; } /// /// Gets the xml response /// /// The xml response public XmlDocument GetXmlResponse() { return xmlResponse; } /// /// Writes the request /// /// File name public void WriteRequest(String fileName) { TextWriter streamWriter = new StreamWriter(fileName, false, Encoding.UTF8); WriteRequest(streamWriter); } /// /// Writes the request /// /// Out stream public void WriteRequest(TextWriter outStream) { xmlRequest.Save(outStream); } /// /// Writes the response /// /// File name public void WriteResponse(String fileName) { TextWriter streamWriter = new StreamWriter(fileName, false, Encoding.UTF8); WriteResponse(streamWriter); } /// /// Writes the response /// /// Out stream public void WriteResponse(TextWriter outStream) { xmlResponse.Save(outStream); } /// /// Execute the specified methodName and parameters /// /// Method name /// Parameters public XmlRpcResponse Execute(string methodName, List parameters){ return Execute(new XmlRpcRequest(methodName, parameters)); } /// /// Execute the specified methodName and parameters /// /// Method name /// Parameters public XmlRpcResponse Execute(string methodName, object[] parameters){ return Execute(new XmlRpcRequest(methodName, parameters)); } /// /// Execute the specified methodName /// /// Method name public XmlRpcResponse Execute(string methodName){ return Execute(new XmlRpcRequest(methodName)); } /// /// Execute the specified request /// /// Request public virtual XmlRpcResponse Execute(XmlRpcRequest request){ this.request = request; XmlDocument xmlRequest = RequestFactory.BuildRequest(request); this.xmlRequest = xmlRequest; XmlDocument xmlResponse = SendRequest(xmlRequest); this.xmlResponse = xmlResponse; this.response = ResponseFactory.BuildResponse(xmlResponse); return response; } } }