void context_BeginRequest(object sender, EventArgs e) { HttpApplication application = sender as HttpApplication; HttpContext context = application.Context; HttpResponse response = context.Response; //--记录服务开始时间 context.Response.AppendHeader(Constant.ESB_HEAD_SERVICE_BEGIN, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff")); //--记录传递过来的跟踪上下文 String traceContextString = context.Request.Headers[Constant.ESB_HEAD_TRACE_CONTEXT]; if (!String.IsNullOrEmpty(traceContextString)) { String[] traceContextParams = traceContextString.Split(":"); ESBTraceContext traceContext = new ESBTraceContext(traceContextParams[0], Int32.Parse(traceContextParams[1]) + 1, traceContextParams[2]); //--将跟踪上下文放入HttpContext,减少程序员传输的工作 context.Items[Constant.ESB_HEAD_TRACE_CONTEXT] = traceContext; } }
/// <summary> /// 动态调用WebService主函数 /// </summary> /// <param name="request"></param> /// <returns></returns> public static ESB.Core.Schema.务响应 DynamicalCallWebService( Boolean needResponse , ESB.Core.Schema.务请求 request , List <BindingTemplate> bindings , Int32 version , EsbView_ServiceConfig serviceConfig , AdvanceInvokeParam invokeParam) { //--记录接收时间并放在请求结束时间中,用于判读ESB在接到请求到开始调用的耗时 DateTime receiveDateTime = DateTime.Now; //--验证并预处理请求参数 InvalidRequest(request); //--获取跟踪上下文 ESBTraceContext esbTraceContext = GetEsbTraceContext(); //--获取到请求对应服务的绑定 BindingTemplate binding = LoadBalance.GetBinding(bindings, serviceConfig.HBPolicy); //--构造调用参数 CallState state = new CallState() { Binding = binding, ServiceConfig = serviceConfig, InvokeParam = invokeParam, Request = request, RequestBeginTime = request.请求时间, RequestEndTime = receiveDateTime, TraceContext = esbTraceContext, ServiceVersion = version, MessageID = Guid.NewGuid().ToString() }; return(CallService(state)); }