Example #1
0
        public const String COMPANY_URL = "http://mb.com";//--公司网址,用于SOAP协议中的基地址

        /// <summary>
        /// 动态调用WebService主函数
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static JN.ESB.Schemas.服务响应 DynamicalCallWebService(
              Boolean needResponse
            , JN.ESB.Schemas.服务请求 request)
        {
            //--记录接收时间并放在请求结束时间中,用于判读ESB在接到请求到开始调用的耗时
            DateTime receiveDateTime = DateTime.Now;

            //--验证并预处理请求参数
            InvalidRequest(request);

            //--获取到请求对应服务的绑定
            EntityList<BindingTemplate> bindings = GetBindings(request);

            //--如果只有一个绑定,且需要返回结果
            if (bindings.Count == 1 && needResponse == true)
            {
                CallState state = new CallState()
                {
                    Binding = bindings[0],
                    Request = request,
                    RequestBeginTime = request.请求时间,
                    RequestEndTime = receiveDateTime
                };

                return CallService(state);
            }
            else //--如果有多个绑定则默认为发布、订阅模式,不需要将每个订阅则的结果都放回给调用方,或者指明是不需要放回结果的情况(单向调用)
            {
                foreach (BindingTemplate binding in bindings)
                {
                    CallState state = new CallState()
                    {
                        Binding = binding,
                        Request = request,
                        RequestBeginTime = request.请求时间,
                        RequestEndTime = receiveDateTime
                    };

                    ThreadPoolX.QueueUserWorkItem(() => CallService(state));
                }
                return GetMultiResponse();
            }
        }
Example #2
0
        public const String COMPANY_URL = "http://mb.com";//--公司网址,用于SOAP协议中的基地址

        /// <summary>
        /// 动态调用WebService主函数
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static JN.ESB.Schemas.务响应 DynamicalCallWebService(
            Boolean needResponse
            , JN.ESB.Schemas.务请求 request)
        {
            //--记录接收时间并放在请求结束时间中,用于判读ESB在接到请求到开始调用的耗时
            DateTime receiveDateTime = DateTime.Now;

            //--验证并预处理请求参数
            InvalidRequest(request);

            //--获取到请求对应服务的绑定
            EntityList <BindingTemplate> bindings = GetBindings(request);

            //--如果只有一个绑定,且需要返回结果
            if (bindings.Count == 1 && needResponse == true)
            {
                CallState state = new CallState()
                {
                    Binding          = bindings[0],
                    Request          = request,
                    RequestBeginTime = request.请求时间,
                    RequestEndTime   = receiveDateTime
                };

                return(CallService(state));
            }
            else //--如果有多个绑定则默认为发布、订阅模式,不需要将每个订阅则的结果都放回给调用方,或者指明是不需要放回结果的情况(单向调用)
            {
                foreach (BindingTemplate binding in bindings)
                {
                    CallState state = new CallState()
                    {
                        Binding          = binding,
                        Request          = request,
                        RequestBeginTime = request.请求时间,
                        RequestEndTime   = receiveDateTime
                    };

                    ThreadPoolX.QueueUserWorkItem(() => CallService(state));
                }
                return(GetMultiResponse());
            }
        }
Example #3
0
        /// <summary>
        /// 根据绑定中的协议类型调用不同的实现方法
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        private static JN.ESB.Schemas.务响应 CallService(CallState callState)
        {
            switch (callState.Binding.BindingType)
            {
            case (int)BindingType.WebService:
                return(SoapClient.CallWebService(callState));

            case (int)BindingType.REST:
                return(RestfulClient.CallRestfulService(callState));

            case (int)BindingType.ASHX:
                return(HandlerClient.CallAshxService(callState));

            case (int)BindingType.WCF_HTTP:
                return(WcfClient.CallWcfService(callState));

            default:
                throw LogUtil.ExceptionAndLog(callState, "未知的绑定类型", callState.Binding.BindingType.ToString(), callState.Binding, callState.Request);
            }
        }
Example #4
0
 /// <summary>
 /// 根据绑定中的协议类型调用不同的实现方法
 /// </summary>
 /// <param name="state"></param>
 /// <returns></returns>
 private static JN.ESB.Schemas.服务响应 CallService(CallState callState)
 {
     switch (callState.Binding.BindingType)
     {
         case (int)BindingType.WebService:
             return SoapClient.CallWebService(callState);
         case (int)BindingType.REST:
             return RestfulClient.CallRestfulService(callState);
         case (int)BindingType.ASHX:
             return HandlerClient.CallAshxService(callState);
         case (int)BindingType.WCF_HTTP:
             return WcfClient.CallWcfService(callState);
         default:
             throw LogUtil.ExceptionAndLog(callState, "未知的绑定类型", callState.Binding.BindingType.ToString(), callState.Binding, callState.Request);
     }
 }