コード例 #1
0
        private void WriteRequest(StreamWriter writer, string methodName, XmlRpcValue parameters)
        {
            writer.Write(REQUEST_BEGIN + methodName + REQUEST_END_METHODNAME);

            if (parameters.IsEmpty)
            {
                writer.Write(PARAMS_TAG);

                if (parameters.Type == XmlRpcType.Array)
                {
                    // If params is an array, each element is a separate parameter
                    for (int i = 0; i < parameters.Count; ++i)
                    {
                        writer.Write(PARAM_TAG);
                        writer.Write(parameters[i].ToXml());
                        writer.Write(PARAM_ETAG);
                    }
                }
                else
                {
                    writer.Write(PARAM_TAG);
                    writer.Write(parameters.ToXml());
                    writer.Write(PARAM_ETAG);
                }

                writer.Write(PARAMS_ETAG);
            }

            writer.Write(REQUEST_END);
        }
コード例 #2
0
        // Run the method, generate response
        public string ExecuteRequest(string request)
        {
            string      response = "";
            XmlRpcValue parms = new XmlRpcValue(), resultValue = new XmlRpcValue();
            string      methodName = ParseRequest(parms, request);

            logger.LogDebug("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)
            {
                logger.LogWarning(fault, "XmlRpcServerConnection::ExecuteRequest: fault {0}", fault.Message);
                response = GenerateFaultResponse(fault.Message, fault.ErrorCode);
            }
            return(response);
        }
コード例 #3
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);

            //Console.WriteLine( "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)
            {
                //Console.WriteLine( "XmlRpcServerConnection::executeRequest: fault {0}.", fault.Message );
                response = generateFaultResponse(fault.Message, fault.ErrorCode);
            }
            return(response);
        }
コード例 #4
0
        public string GenerateFaultResponse(string errorMsg, int errorCode = -1)
        {
            const string bodyBegin = "<?xml version=\"1.0\"?>\r\n<methodResponse><fault>\r\n";
            const string bodyEnd   = "\r\n</fault></methodResponse>\r\n";

            var faultStruct = new XmlRpcValue();

            faultStruct.Set(FAULTCODE, errorCode);
            faultStruct.Set(FAULTSTRING, errorMsg);
            string body   = bodyBegin + faultStruct.ToXml() + bodyEnd;
            string header = GenerateHeader(body);

            return(header + body);
        }
コード例 #5
0
        public string generateFaultResponse(string errorMsg, int errorCode = -1)
        {
            const string RESPONSE_1 = "<?xml version=\"1.0\"?>\r\n<methodResponse><fault>\r\n\t";
            const string RESPONSE_2 = "\r\n</fault></methodResponse>\r\n";

            var 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);
        }