예제 #1
0
        /// <summary>Send the request to the server.</summary>
        /// <param name="url"><c>String</c> The url of the XML-RPC server.</param>
        /// <param name="timeout">AMount of time in milliseconds to wait for timeout</param>
        /// <returns><c>XmlRpcResponse</c> The response generated.</returns>
        public XmlRpcResponse Send(string url, int timeout = 0)
        {
            var request = (HttpWebRequest)WebRequest.Create(url);

            if (request == null)
            {
                throw new XmlRpcException(XmlRpcErrorCodes.TRANSPORT_ERROR,
                                          XmlRpcErrorCodes.TRANSPORT_ERROR_MSG + ": Could not create request with " + url);
            }
            request.Method      = "POST";
            request.ContentType = "text/xml";
            request.AllowWriteStreamBuffering = true;
            if (timeout > 0)
            {
                request.Timeout = timeout;
            }

            var stream = request.GetRequestStream();
            var xml    = new XmlTextWriter(stream, _encoding);

            _serializer.Serialize(xml, this);
            xml.Flush();
            xml.Close();

            var response = (HttpWebResponse)request.GetResponse();
            var input    = new StreamReader(response.GetResponseStream());

            var resp = (XmlRpcResponse)_deserializer.Deserialize(input);

            input.Close();
            response.Close();
            return(resp);
        }
예제 #2
0
        /// <summary>Send the request to the server.</summary>
        /// <param name="url"><c>String</c> The url of the XML-RPC server.</param>
        /// <returns><c>XmlRpcResponse</c> The response generated.</returns>
        public XmlRpcResponse Send(String url)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            if (request == null)
            {
                throw new XmlRpcException(XmlRpcErrorCodes.TRANSPORT_ERROR,
                                          XmlRpcErrorCodes.TRANSPORT_ERROR_MSG + ": Could not create request with " + url);
            }
            request.Method      = "POST";
            request.ContentType = "text/xml";
            request.UserAgent   = "MJZSOFT XML RPC 1.0.0 (MJZ HTTP Transport)";
            request.KeepAlive   = false;
            request.AllowWriteStreamBuffering = true;

            Stream        stream = request.GetRequestStream();
            XmlTextWriter xml    = new XmlTextWriter(stream, _encoding);

            _serializer.Serialize(xml, this);
            xml.Flush();
            xml.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader    input    = new StreamReader(response.GetResponseStream());

            XmlRpcResponse resp = (XmlRpcResponse)_deserializer.Deserialize(input);

            input.Close();
            response.Close();
            return(resp);
        }
예제 #3
0
        /// <summary>Send the request to the server.</summary>
        /// <param name="url"><c>String</c> The url of the XML-RPC server.</param>
        /// <returns><c>XmlRpcResponse</c> The response generated.</returns>
        public XmlRpcResponse Send(string url, int timeout = 100000, RemoteCertificateValidationCallback certCallBack = null)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            if (request == null)
            {
                throw new XmlRpcException(XmlRpcErrorCodes.TRANSPORT_ERROR,
                                          XmlRpcErrorCodes.TRANSPORT_ERROR_MSG + ": Could not create request with " + url);
            }
            request.Method      = "POST";
            request.ContentType = "text/xml";
            request.AllowWriteStreamBuffering = true;
            request.Timeout = timeout;
            if (certCallBack != null)
            {
                request.ServerCertificateValidationCallback = certCallBack;
            }

            using (Stream stream = request.GetRequestStream())
                using (XmlTextWriter xml = new XmlTextWriter(stream, m_encoding))
                {
                    _serializer.Serialize(xml, this);
                    xml.Flush();
                }

            XmlRpcResponse resp;

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                using (StreamReader input = new StreamReader(response.GetResponseStream()))
                    resp = (XmlRpcResponse)_deserializer.Deserialize(input);
            return(resp);
        }
예제 #4
0
        /// <summary>Send the request to the server.</summary>
        /// <param name="url"><c>String</c> The url of the XML-RPC server.</param>
        /// <param name="timeout">Milliseconds before the connection times out.</param>
        /// <returns><c>XmlRpcResponse</c> The response generated.</returns>
        public XmlRpcResponse Send(String url, int timeout)
        {
            // Override SSL authentication mechanisms
            ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            if (request == null)
            {
                throw new XmlRpcException(XmlRpcErrorCodes.TRANSPORT_ERROR,
                                          XmlRpcErrorCodes.TRANSPORT_ERROR_MSG + ": Could not create request with " + url);
            }
            request.Method      = "POST";
            request.ContentType = "text/xml";
            request.AllowWriteStreamBuffering = true;
            request.Timeout = timeout;

            Stream        stream = request.GetRequestStream();
            XmlTextWriter xml    = new XmlTextWriter(stream, _encoding);

            _serializer.Serialize(xml, this);
            xml.Flush();
            xml.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader    input    = new StreamReader(response.GetResponseStream());

            XmlRpcResponse resp = (XmlRpcResponse)_deserializer.Deserialize(input);

            input.Close();
            response.Close();
            return(resp);
        }
예제 #5
0
        /// <summary>Send the request to the server.</summary>
        /// <param name="url"><c>String</c> The url of the XML-RPC server.</param>
        /// <returns><c>XmlRpcResponse</c> The response generated.</returns>
        public XmlRpcResponse Send(String url)
        {
            RequestSettings settings = RequestSettings.getInstance();
            HttpWebRequest  request  = (HttpWebRequest)WebRequest.Create(url);

            settings.Apply(request);

            if (request == null)
            {
                throw new XmlRpcException(XmlRpcErrorCodes.TRANSPORT_ERROR,
                                          XmlRpcErrorCodes.TRANSPORT_ERROR_MSG + ": Could not create request with " + url);
            }
            request.Method      = "POST";
            request.ContentType = "text/xml";
            request.AllowWriteStreamBuffering = true;

            Stream        stream = request.GetRequestStream();
            XmlTextWriter xml    = new XmlTextWriter(stream, _encoding);

            _serializer.Serialize(xml, this);
            xml.Flush();
            xml.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader    input    = new StreamReader(response.GetResponseStream());

            XmlRpcResponse resp = (XmlRpcResponse)_deserializer.Deserialize(input);

            input.Close();
            response.Close();
            return(resp);
        }
        /// <summary>Send the request to the server.</summary>
        /// <param name="url"><c>String</c> The url of the XML-RPC server.</param>
        /// <returns><c>XmlRpcResponse</c> The response generated.</returns>
        public XmlRpcResponse Send(String url)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            if (request == null)
            {
                throw new XmlRpcException(XmlRpcErrorCodes.TRANSPORT_ERROR,
                                          XmlRpcErrorCodes.TRANSPORT_ERROR_MSG + ": Could not create request with " + url);
            }
            request.Method      = "POST";
            request.ContentType = "text/xml";
            request.AllowWriteStreamBuffering = true;
            request.KeepAlive = !_disableKeepAlive;
            request.Timeout   = 30000;

            using (Stream stream = request.GetRequestStream())
            {
                using (XmlTextWriter xml = new XmlTextWriter(stream, Encoding.ASCII))
                {
                    _serializer.Serialize(xml, this);
                    xml.Flush();
                }
            }

            XmlRpcResponse resp;

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream s = response.GetResponseStream())
                {
                    using (StreamReader input = new StreamReader(s))
                    {
                        string inputXml = input.ReadToEnd();

                        try
                        {
                            resp = (XmlRpcResponse)_deserializer.Deserialize(inputXml);
                        }
                        catch (Exception e)
                        {
                            RequestResponse = inputXml;
                            throw e;
                        }
                    }
                }
            }

            return(resp);
        }
예제 #7
0
        /// <summary>Send the request to the server.</summary>
        /// <param name="url"><c>String</c> The url of the XML-RPC server.</param>
        /// <returns><c>XmlRpcResponse</c> The response generated.</returns>
        public XmlRpcResponse Send(String url)
        {
            // Override SSL authentication mechanisms
            ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
            //ServicePointManager.ServerCertificateValidationCallback +=
            //    delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
            //    { return true; };

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            if (request == null)
            {
                throw new XmlRpcException(XmlRpcErrorCodes.TRANSPORT_ERROR,
                                          XmlRpcErrorCodes.TRANSPORT_ERROR_MSG + ": Could not create request with " + url);
            }
            request.Method      = "POST";
            request.ContentType = "text/xml";
            request.AllowWriteStreamBuffering = true;
            request.KeepAlive = false;
            request.Timeout   = 15000; // miliseconds adjust as you see fit

            Stream        stream = request.GetRequestStream();
            XmlTextWriter xml    = new XmlTextWriter(stream, _encoding);

            _serializer.Serialize(xml, this);
            xml.Flush();
            xml.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader    input    = new StreamReader(response.GetResponseStream());

            XmlRpcResponse resp = (XmlRpcResponse)_deserializer.Deserialize(input);

            input.Close();
            response.Close();
            return(resp);
        }