Esempio n. 1
0
        public void OnResponse(ref HTTPRequestStruct hTTPRequestStruct, ref HTTPResponseStruct responseStruct)
        {
            char[] base64chars = Encoding.UTF8.GetChars(hTTPRequestStruct.BodyData);

            WriteLog("Base64Chars: " + new String(base64chars));

            byte[] encBytes = Convert.FromBase64CharArray(base64chars, 0, base64chars.Length);

            XmlRpcRequest xmlRequest = XmlRpcRequest.ParseXmlRpcRequest(encryptor.Decrypt(encBytes));

            WriteLog("\n\n MethodCall: " + xmlRequest.ObjectName + "." + xmlRequest.MethodName);
            WriteLog("\n\n Params ");
            foreach (Object o in xmlRequest.Params)
                WriteLog("\n " + o);

            Object handler = null;

            if(handlers.ContainsKey(xmlRequest.ObjectName))
                handler = handlers[xmlRequest.ObjectName];

            if (handler == null)
                throw new XmlRpcException(String.Format("No handler registered for \"{0}\"", xmlRequest.ObjectName));

            Type handlerType = handler.GetType();
            MethodInfo methodInfo = handlerType.GetMethod(xmlRequest.MethodName);

            if (methodInfo == null)
                throw new MissingMethodException("Method " + xmlRequest.MethodName + " not found.");

            Object returnValue = null;

            lock (this)
            {
                returnValue = methodInfo.Invoke(handler, xmlRequest.Params.ToArray());
            }

            if (returnValue == null)
                throw new XmlRpcException("Method returned NULL.");

            XmlRpcResponse response = new XmlRpcResponse(returnValue);
            MemoryStream ms = new MemoryStream();
            response.WriteXml(new XmlTextWriter(ms, UTF8Encoding.UTF8));

            responseStruct.BodyData = UTF8Encoding.UTF8.GetBytes(Convert.ToBase64String(encryptor.Encrypt(ms.ToArray())));
            responseStruct.BodySize = responseStruct.BodyData.Length;
        }
Esempio n. 2
0
 private void PrepareFaultResponse(ref HTTPResponseStruct responseStruct, string faultMessage, int faultCode)
 {
     XmlRpcResponse response = new XmlRpcResponse(faultMessage, faultCode);
     MemoryStream ms = new MemoryStream();
     response.WriteXml(new XmlTextWriter(ms, UTF8Encoding.UTF8));
     responseStruct.BodyData = UTF8Encoding.UTF8.GetBytes(Convert.ToBase64String(this.Parent.encryptor.Encrypt(ms.ToArray())));
     responseStruct.BodySize = responseStruct.BodyData.Length;
 }