Esempio n. 1
0
        public MethodResponse Execute()
        {
            StreamWriter sw = null;

            // prepare data

            String xmlstr = _method_call.ToXml();

            // prepare request
            HttpWebRequest hwreq = (HttpWebRequest)WebRequest.Create(url);

            hwreq.Method        = "POST";
            hwreq.UserAgent     = "tocorre.XmlRpc .NET Client"; // make this a property later
            hwreq.ContentType   = "text/xml";
            hwreq.ContentLength = xmlstr.Length;

            try
            {
                sw = new StreamWriter(hwreq.GetRequestStream());
                sw.Write(xmlstr);
            }
            catch (WebException we)
            {
                // some unexpected error occurred. Log it?
                Console.WriteLine(we.Message);
            }
            finally
            {
                sw.Close();
            }

            // read response
            HttpWebResponse hwresp          = (HttpWebResponse)hwreq.GetResponse();
            MethodResponse  method_response = null;

            using (StreamReader sr = new StreamReader(hwresp.GetResponseStream()))
            {
                String result = sr.ReadToEnd();
                method_response = new MethodResponse(result);
                sr.Close();
            }
            return(method_response);
        }
Esempio n. 2
0
        public MethodResponse Execute()
        {
            StreamWriter sw = null;

            // prepare data

            String xmlstr = _method_call.ToXml();

            // prepare request
            HttpWebRequest hwreq = (HttpWebRequest)WebRequest.Create(url);
            hwreq.Method = "POST";
            hwreq.UserAgent = "tocorre.XmlRpc .NET Client"; // make this a property later
            hwreq.ContentType = "text/xml";
            hwreq.ContentLength = xmlstr.Length;

            try
            {
                sw = new StreamWriter(hwreq.GetRequestStream());
                sw.Write(xmlstr);
            }
            catch (WebException we)
            {
                // some unexpected error occurred. Log it?
                Console.WriteLine(we.Message);
            }
            finally
            {
                sw.Close();
            }

            // read response
            HttpWebResponse hwresp = (HttpWebResponse)hwreq.GetResponse();
            MethodResponse method_response = null;
            using (StreamReader sr = new StreamReader(hwresp.GetResponseStream()))
            {
                String result = sr.ReadToEnd();
                method_response = new MethodResponse(result);
                sr.Close();
            }
            return method_response;
        }