protected ServiceOperationInfo BuildServiceOperationInfoObject(MethodCallExpression info) { var methodInfo = new ServiceOperationInfo(); methodInfo.MethodName = info.Method.Name; methodInfo.RequestType = info.Method.GetParameters()[0].ParameterType; methodInfo.ResponseType = info.Method.ReturnParameter.ParameterType; methodInfo.ClassName = info.Object.Type.FullName; return(methodInfo); }
protected virtual void CallService <TViewModel, TRequest, TResponse, TClient>(TViewModel model, Expression <Func <TClient, TRequest, TResponse> > methodFunc) where TRequest : class where TResponse : class where TClient : IDisposable { ServiceOperationInfo operationInfo = GetServiceOperationInfoFromMethodFuncWithRequestAndResponse(methodFunc); MapperFactory mapperFactory = new MapperFactory(); var mapper = mapperFactory.CreateMapper <TViewModel, TRequest, TResponse>(operationInfo.MethodName); TRequest request = mapper.Map(model); TResponse response = GetResponseFromServiceCall(request, methodFunc); mapper.Map(response, model); }
protected TResponse GetResponseFromServiceCall <TRequest, TResponse, TClient>(TRequest request, Expression <Func <TClient, TRequest, TResponse> > methodFunc) where TRequest : class where TResponse : class where TClient : IDisposable { TResponse response = null; ServiceOperationInfo info = GetServiceOperationInfoFromMethodFuncWithRequestAndResponse(methodFunc); using (var c = Create <TClient>()) { Func <TClient, TRequest, TResponse> theFunc = methodFunc.Compile(); response = theFunc(c, request); } return(response); }