/// <summary> /// /// </summary> /// <typeparam name="TContext"></typeparam> /// <param name="actionContext"></param> /// <param name="principal"></param> public static void SetPrincipalInContext <TContext>(ActionContextBase <TContext> actionContext, IGenericTokenPrincipal principal) where TContext : ActionContextBase <TContext>, new() { actionContext.NullCheck("actionContext"); principal.NullCheck("principal"); GenericTicketTokenContainer container = principal.GetGenericTicketTokenContainer(); GenericTicketPrincipal genericPrincipal = new GenericTicketPrincipal(container.User, container.RealUser); actionContext.Context["Principal"] = genericPrincipal; }
/// <summary> /// 序列化服务调用的请求信息 /// </summary> /// <param name="messageVersion"></param> /// <param name="parameters"></param> /// <returns></returns> public System.ServiceModel.Channels.Message SerializeRequest(System.ServiceModel.Channels.MessageVersion messageVersion, object[] parameters) { Dictionary <string, object> paramNameValuePair = new Dictionary <string, object>(); for (int i = 0; i < _OperationDesc.Messages[0].Body.Parts.Count; i++) { string paramName = _OperationDesc.Messages[0].Body.Parts[i].Name; object paramVal = parameters[i]; paramNameValuePair.Add(paramName, paramVal); } paramNameValuePair["__ConnectionMappings"] = GetConnectionMappings(); paramNameValuePair["__Context"] = WfClientServiceBrokerContext.Current.Context; //if (WfClientServiceBrokerContext.Current.Context.ContainsKey("TenantCode") == false && // TenantContext.Current.Enabled) if (TenantContext.Current.Enabled) { WfClientServiceBrokerContext.Current.Context["TenantCode"] = TenantContext.Current.TenantCode; } IGenericTokenPrincipal principal = GetPrincipal(WfClientServiceBrokerContext.Current); if (principal != null) { paramNameValuePair["__TokenContainer"] = principal.GetGenericTicketTokenContainer(); } string paramJson = JSONSerializerExecute.SerializeWithType(paramNameValuePair); Message requestMessage = WcfUtils.CreateJsonFormatRequestMessage(messageVersion, _OperationDesc.Messages[0].Action, paramJson); requestMessage.Headers.To = _MessageDestinationUri; return(requestMessage); }