Esempio n. 1
0
        /// <summary>
        /// 通过调用UFX接口同步发送请求,调用前必须确保已经注册了功能号和回调代理,即调用Register函数注册。
        /// 同一功能号注册多次只会保留最后一次结果。
        /// </summary>
        /// <param name="message">CT2BizMessage对象的实例,包含用户信息,功能号,请求参数等信息</param>
        /// <returns>返回正值表示发送句柄,否则表示失败。</returns>
        public int SendSync(CT2BizMessage message)
        {
            int iRet = _conn.SendBizMsg(message, (int)SendType.Sync);

            if (iRet < 0)
            {
                string msg = string.Format("一般交易业务同步发送数据失败! 错误码:{0}, 错误消息:{1}", iRet, _conn.GetErrorMsg(iRet));
                logger.Error(msg);
                return(iRet);
            }

            CT2BizMessage bizMessage = null;
            int           retCode    = _conn.RecvBizMsg(iRet, out bizMessage, (int)_timeOut, 1);

            if (retCode < 0)
            {
                string msg = "一般交易业务同步接收出错: " + _conn.GetErrorMsg(retCode);
                logger.Error(msg);
                return((int)ConnectionCode.ErrorSendMsg);
            }

            int iFunction = bizMessage.GetFunction();

            if (Enum.IsDefined(typeof(UFXFunctionCode), iFunction))
            {
                return(HandleReceivedBizMsg(SendType.Sync, (UFXFunctionCode)iFunction, retCode, bizMessage));
            }
            else
            {
                string msg = string.Format("一般交易业务未支持的功能号:{0}", iFunction);
                logger.Error(msg);
                return((int)ConnectionCode.ErrorNoFunctionCode);
            }
        }
Esempio n. 2
0
        public int SendSync(CT2BizMessage message)
        {
            int iRet = _conn.SendBizMsg(message, 0);

            if (iRet < 0)
            {
                logger.Error(string.Format("同步发送数据失败! 错误码:{0}, 错误消息:{1}", iRet, _conn.GetErrorMsg(iRet)));
                return(iRet);
            }

            CT2BizMessage bizMessage = null;
            int           retCode    = _conn.RecvBizMsg(iRet, out bizMessage, (int)_timeOut, 1);

            if (retCode < 0)
            {
                logger.Error("同步接收出错: " + _conn.GetErrorMsg(retCode));
                return((int)ConnectionCode.ErrorSendMsg);
            }

            int iFunction = bizMessage.GetFunction();

            if (Enum.IsDefined(typeof(FunctionCode), iFunction))
            {
                FunctionCode functionCode = (FunctionCode)Enum.ToObject(typeof(FunctionCode), iFunction);
                if (_bizCallbackMap.ContainsKey(functionCode) && _bizCallbackMap[functionCode] != null)
                {
                    retCode = _bizCallbackMap[functionCode](bizMessage);
                }
                else
                {
                    string msg = string.Format("异步接收数据回调函数找不到 - 功能号:{0}", iFunction);
                    logger.Error(msg);
                    return((int)ConnectionCode.ErrorNoCallback);
                }
            }
            else
            {
                string msg = string.Format("为支持的功能号:{0}", iFunction);
                logger.Error(msg);
                return((int)ConnectionCode.ErrorNoFunctionCode);
            }

            return(retCode);
        }