예제 #1
0
        private static WcfSetting GetWcfSetting(Type type)
        {
            WcfSetting setting = null;

            try
            {
                if (type.IsInterface)
                {
                    using (var client = WcfServiceClientFactory.CreateServiceClient <IWcfConfigService>())
                    {
                        setting = client.Channel.GetClientSetting(type.FullName, CommonConfiguration.MachineIP);
                    }
                }
                else
                {
                    using (var client = WcfServiceClientFactory.CreateServiceClient <IWcfConfigService>())
                    {
                        setting = client.Channel.GetServerSetting(type.FullName, CommonConfiguration.MachineIP);
                    }
                }
            }
            catch (Exception ex)
            {
                ex.Handle(WcfLogProvider.ModuleName, "WcfSettingManager", "GetWcfSetting");
            }
            return(setting);
        }
예제 #2
0
        private static WcfServiceConfig GetWcfServiceConfiguration(Type serviceType)
        {
            var version = serviceType.GetInterfaces().Where(type => !type.Assembly.GlobalAssemblyCache).First().Assembly.GetName().Version;

            try
            {
                using (var scf = WcfServiceClientFactory.CreateServiceClient <IWcfConfigService>())
                {
                    return(scf.Channel.GetWcfService(serviceType.FullName, version.Major + "." + version.Minor, CommonConfiguration.MachineIP));
                }
            }
            catch (Exception ex)
            {
                ex.Handle(WcfLogProvider.ModuleName, "WcfServiceHostFactory", "GetWcfServiceConfiguration");
                throw;
            }
        }
예제 #3
0
        private static WcfClientEndpointConfig GetWcfClientEndpointConfiguration(Type serviceContractType)
        {
            var version       = serviceContractType.Assembly.GetName().Version;
            var versionstring = version.Major + "." + version.Minor;

            try
            {
                using (var scf = WcfServiceClientFactory.CreateServiceClient <IWcfConfigService>())
                {
                    return(scf.Channel.GetWcfClientEndpoint(serviceContractType.FullName, versionstring, CommonConfiguration.MachineIP));
                }
            }
            catch (Exception ex)
            {
                ex.Handle(WcfLogProvider.ModuleName, "WcfServiceClientFactory", "GetWcfClientEndpointConfiguration");
                throw;
            }
        }
예제 #4
0
        public override IMessage Invoke(IMessage msg)
        {
            using (var client = WcfServiceClientFactory.CreateServiceClient <T>())
            {
                var channel = client.Channel;
                IMethodCallMessage   methodCall   = (IMethodCallMessage)msg;
                IMethodReturnMessage methodReturn = null;
                object[]             copiedArgs   = Array.CreateInstance(typeof(object), methodCall.Args.Length) as object[];
                methodCall.Args.CopyTo(copiedArgs, 0);

                bool isSuccessuful = false;
                var  stopwatch     = Stopwatch.StartNew();

                try
                {
                    //WcfClientStateService.BeginInvoke(typeof(T).FullName);
                    object returnValue = methodCall.MethodBase.Invoke(channel, copiedArgs);

                    methodReturn = new ReturnMessage(returnValue,
                                                     copiedArgs,
                                                     copiedArgs.Length,
                                                     methodCall.LogicalCallContext,
                                                     methodCall);
                    isSuccessuful = true;
                    //WcfClientStateService.EndInvoke(typeof(T).FullName, stopwatch.ElapsedMilliseconds, true);
                }
                catch (Exception ex)
                {
                    try
                    {
                        //WcfClientStateService.EndInvoke(typeof(T).FullName, stopwatch.ElapsedMilliseconds, false);
                        var exception = ex;
                        if (ex.InnerException != null)
                        {
                            exception = ex.InnerException;
                        }
                        if (typeof(T) != typeof(IWcfConfigService) && typeof(T) != typeof(IConfigServer))
                        {
                            if (ClientApplicationContext.Current != null)
                            {
                                var exceptionID = ClientApplicationContext.Current.ServerExceptionID ?? "";
                                exception.HelpLink = "服务端异常Id:" + exceptionID;
                                if (WcfLogSetting.Enabled && WcfLogSetting.ExceptionInfoSetting.Enabled)
                                {
                                    ((ExceptionService)AppInfoCenterService.ExceptionService).WcfUnhandledClientException(exception, typeof(T).FullName,
                                                                                                                          exceptionID, ClientApplicationContext.Current.RequestIdentity);
                                }
                            }
                            else
                            {
                                if (WcfLogSetting.Enabled && WcfLogSetting.ExceptionInfoSetting.Enabled)
                                {
                                    ((ExceptionService)AppInfoCenterService.ExceptionService).WcfUnhandledClientException(exception, typeof(T).FullName,
                                                                                                                          "", "");
                                }
                            }
                        }

                        if (safe)
                        {
                            methodReturn = new ReturnMessage(null,
                                                             copiedArgs,
                                                             copiedArgs.Length,
                                                             methodCall.LogicalCallContext,
                                                             methodCall);
                        }
                        else
                        {
                            methodReturn = new ReturnMessage(exception, methodCall);
                        }
                    }
                    catch (Exception exx)
                    {
                        LocalLoggingService.Error("ServiceRealProxy.Invoke.catch出现异常:{0}", exx.ToString());
                    }
                }
                finally
                {
                    if (typeof(T) != typeof(IWcfConfigService) && typeof(T) != typeof(IConfigServer))
                    {
                        if (WcfLogSetting.Enabled && WcfLogSetting.InvokeInfoSetting.Enabled)
                        {
                            var log = WcfLogProvider.GetClientInvokeLog(
                                typeof(T).FullName,
                                "ServiceRealProxy.Invoke",
                                stopwatch.ElapsedMilliseconds,
                                isSuccessuful,
                                methodCall.MethodName,
                                ClientApplicationContext.Current);
                            MongodbService.MongodbInsertService.Insert(log);
                        }
                    }
                }
                return(methodReturn);
            }
        }