Example #1
0
 /// <summary>
 /// Deserializes string response to MethodResponse object. If error, it returns to FaultException object.
 /// </summary>
 /// <param name="xmlRpcResponse">string response after sending request</param>
 /// <returns>MethodResponse object</returns>
 public static MethodResponse XmlRpcDeserialize(string xmlRpcResponse)
 {
     using (var reader = XmlReader.Create(new StringReader(xmlRpcResponse)))
     {
         XmlRpcSerialization deserializer = new XmlRpcSerialization();
         MethodResponse      responseCcu  = (MethodResponse)deserializer.ReadObject(reader);
         return(responseCcu);
     }
 }
Example #2
0
        /// <summary>
        /// Sends request to server via HTTP and deserialize string response
        /// </summary>
        /// <param name="request">MethodCall object</param>
        /// <returns>MethodResponse object</returns>
        public async Task <MethodResponse> SendRequestAndDeserialize(MethodCall request)
        {
            if (m_Uri != null)
            {
                string xmlRpcString   = XmlRpcSerialization.XmlRpcSerialize(request);
                string responseString = await this.postHttp(xmlRpcString);

                MethodResponse response = XmlRpcSerialization.XmlRpcDeserialize(responseString);

                return(response);
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
Example #3
0
        /// <summary>
        /// Serializes MethodCall object into string
        /// </summary>
        /// <param name="methodCall">MethodCall object need to be serialized</param>
        /// <returns>serialized string</returns>
        public static string XmlRpcSerialize(MethodCall methodCall)
        {
            string data;

            using (MemoryStream ms = new MemoryStream())
            {
                XmlRpcSerialization serializer = new XmlRpcSerialization();
                serializer.WriteObject(ms, methodCall);

                ArraySegment <byte> buff;
                if (ms.TryGetBuffer(out buff))
                {
                    data = Encoding.UTF8.GetString(buff.ToArray());
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            return(data);
        }
Example #4
0
 /// <summary>
 /// Serializes request as Method Call object into XML-type
 /// </summary>
 /// <param name="request">MethodCall object</param>
 /// <returns>serialized string</returns>
 public string SerializeRequest(MethodCall request)
 {
     return(XmlRpcSerialization.XmlRpcSerialize(request));
 }
Example #5
0
 /// <summary>
 /// Deserializes Response from string
 /// </summary>
 /// <param name="responseString">response string</param>
 /// <returns>MethodResponse object</returns>
 public MethodResponse DeserializeResponse(string responseString)
 {
     return(XmlRpcSerialization.XmlRpcDeserialize(responseString));
 }