Ejemplo n.º 1
0
        public void Add(DTOBase entityDTO)
        {
            try
            {
                //var header = new MessageHeader<ProfileContext>();
                //OperationContext.Current.OutgoingMessageHeaders.Add(header.GetUntypedHeader("Int32", "System"));
                Guid result = Guid.Empty;

                var contextChannel = _channel as IContextChannel;
                if (contextChannel != null)
                {
                    using (var scope = new OperationContextScope(contextChannel))
                    {
                        var contextManager = new ServiceContextManager();
                        ServiceContextManager.Current = contextManager;
                        _channel.Add(new List<object>() { entityDTO });
                    }
                }
                else
                {
                    //WCF调用方式 理论上应该不会走到这里,在本地调用方式进行处理

                }

            }
            catch (FaultException<ExceptionBase> seb)
            {
                //系统异常
                //TO DO Log...
                if (seb.Detail != null)
                    throw seb.Detail;
                else
                    throw new ExceptionBase();
            }
            catch (FaultException<UnhandledException> unex)
            {
                //服务端未处理异常
                //TO DO Log...
                throw unex.Detail;
            }
            catch (FaultException fe)
            {
                throw fe.InnerException;
            }
            catch (Exception e)
            {
                //传输过程中出现的异常
                //TO DO Log...
                Console.WriteLine(e.Message);
                throw;
            }
            finally
            {
                var realChannel = _channel as IDisposable;
                if (realChannel != null)
                {
                    realChannel.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        public Guid NotSupported(bool isSucceed)
        {
            try
            {
                //var header = new MessageHeader<ProfileContext>();
                //OperationContext.Current.OutgoingMessageHeaders.Add(header.GetUntypedHeader("Int32", "System"));
                Guid result = Guid.Empty;

                var contextChannel = _channel as IContextChannel;
                if (contextChannel != null)
                {
                    using (var scope = new OperationContextScope(contextChannel))
                    {
                        var contextManager = new ServiceContextManager();
                        ServiceContextManager.Current = contextManager;
                        result = _channel.NotSupported(isSucceed);
                    }
                }
                else
                {
                    //理论上应该不会走到这里
                    result = _channel.NotSupported(isSucceed);
                    Debug.Assert(true, "服务 Agent里打开的Channel不是 IContextChannel 类型,神马情况?需要确认一下");
                }
                return result;
            }
            catch (FaultException<ExceptionBase> seb)
            {
                //系统异常
                //TO DO Log...
                if (seb.Detail != null)
                    throw seb.Detail;
                else
                    throw new ExceptionBase();
            }
            catch (FaultException<UnhandledException> unex)
            {
                //服务端未处理异常
                //TO DO Log...
                throw unex.Detail;
            }
            catch (Exception e)
            {
                //传输过程中出现的异常
                //TO DO Log...
                Console.WriteLine(e.Message);
                throw;
            }
            finally
            {
                var realChannel = _channel as IDisposable;
                if (realChannel != null)
                {
                    realChannel.Dispose();
                }
            }
        }