示例#1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        byte[] byteData = null;
        try
        {
            if (context == null)
            {
                context = ContextUtil.getInstance(Server.MapPath("."));
                encrypt = context.getOuterEncrypt();
            }

            if (encoder == null)
            {
                encoder = ParamEncoder.getInstance();
            }
            if (decoder == null)
            {
                decoder = ParamDecoder.getInstance();
            }

            encoder.outEncoder = context.getOuterResolve();
            decoder.outDecoder = context.getOuterResolve();

            Stream input = Request.InputStream;

            if (input.CanRead)
            {
                byteData = new byte[input.Length];
                input.Read(byteData, 0, (int)input.Length);
                input.Close();
                input.Dispose();

                // 解密
                if (encrypt != null)
                {
                    byteData = encrypt.decrypt(byteData);
                }

                dataVo = decoder.decoder(byteData);
                Type serviceCls = context.getService(context.getServiceNameSpace() + "." + dataVo.ServiceName);

                MethodInfo method = serviceCls.GetMethod(dataVo.MethodName);

                object result = method.Invoke(System.Activator.CreateInstance(serviceCls), dataVo.Param);

                dataVo.Result       = result;
                dataVo.ResultStatus = "success";
                byte[] resultData = encoder.encode(dataVo);

                if (encrypt != null)
                {
                    resultData = encrypt.encrypt(resultData);
                }

                output = Response.OutputStream;
                output.Write(resultData, 0, resultData.Length);
                output.Flush();
                output.Close();
                output.Dispose();
            }
            else
            {
            }
        }
        catch (Exception exc)
        {
            if (dataVo == null && byteData != null)
            {
                dataVo = decoder.decoder(byteData);
            }
            if (dataVo == null)
            {
                dataVo = new DataVO();
            }
            dataVo.ResultStatus = "error";
            dataVo.ErrorMessage = exc.ToString();
            byte[] resultData = encoder.encode(dataVo);

            if (encrypt != null)
            {
                resultData = encrypt.encrypt(resultData);
            }
            output = Response.OutputStream;
            output.Write(resultData, 0, resultData.Length);
            output.Flush();
            output.Close();
            output.Dispose();
        }
    }