Esempio n. 1
0
        // Run the method, generate _response string
        public string executeRequest(string _request)
        {
            string      _response = "";
            XmlRpcValue parms = new XmlRpcValue(), resultValue = new XmlRpcValue();
            string      methodName = parseRequest(parms, _request);

            XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.WARNING, "XmlRpcServerConnection::executeRequest: server calling method '{0}'", methodName);

            try
            {
                if (!executeMethod(methodName, parms, resultValue) &&
                    !executeMulticall(methodName, parms, resultValue))
                {
                    _response = generateFaultResponse(methodName + ": unknown method name");
                }
                else
                {
                    _response = generateResponse(resultValue.toXml());
                }
            }
            catch (XmlRpcException fault)
            {
                XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.WARNING, "XmlRpcServerConnection::executeRequest: fault {0}.", fault.Message);
                _response = generateFaultResponse(fault.Message, fault.getCode());
            }
            return(_response);
        }
Esempio n. 2
0
        private string generateRequestStr(string methodName, XmlRpcValue parameters)
        {
            string body = REQUEST_BEGIN;

            body += methodName;
            body += REQUEST_END_METHODNAME;

            // If params is an array, each element is a separate parameter
            if (parameters.Valid)
            {
                body += PARAMS_TAG;
                if (parameters.Type == XmlRpcValue.ValueType.TypeArray)
                {
                    for (int i = 0; i < parameters.Length; ++i)
                    {
                        body += PARAM_TAG;
                        body += parameters[i].toXml();
                        body += PARAM_ETAG;
                    }
                }
                else
                {
                    body += PARAM_TAG;
                    body += parameters.toXml();
                    body += PARAM_ETAG;
                }

                body += PARAMS_ETAG;
            }
            body += REQUEST_END;
            return(body);
        }
Esempio n. 3
0
        public string generateFaultResponse(string errorMsg, int errorCode = -1)
        {
            string RESPONSE_1 = "<?xml version=\"1.0\"?>\r\n<methodResponse><fault>\r\n\t";
            string RESPONSE_2 = "\r\n</fault></methodResponse>\r\n";

            XmlRpcValue faultStruct = new XmlRpcValue();

            faultStruct.Set(FAULTCODE, errorCode);
            faultStruct.Set(FAULTSTRING, errorMsg);
            string body   = RESPONSE_1 + faultStruct.toXml() + RESPONSE_2;
            string header = generateHeader(body);

            return(header + body);
        }