public void Configure(string connectionString, string providerName, string baseDirectory)
 {
     Trace.WriteLine("Current AppDomain: " + AppDomain.CurrentDomain.FriendlyName);
     Trace.WriteLine("Current AppDomain: " + AppDomain.CurrentDomain.BaseDirectory);
     _manager        = new ServiceContextManager(connectionString, providerName, baseDirectory);
     _serviceContext = _manager.Services;
 }
Exemplo n.º 2
0
        public ResultDTO Do()
        {
            try
            {
                //var header = new MessageHeader<ProfileContext>();
                //OperationContext.Current.OutgoingMessageHeaders.Add(header.GetUntypedHeader("Int32", "System"));

                ResultDTO result = null;
                var contextChannel = _channel as IContextChannel;
                if (contextChannel != null)
                {
                    using (var scope = new OperationContextScope(contextChannel))
                    {
                        var contextManager = new ServiceContextManager<ServiceContext>();
                        ServiceContextManager<ServiceContext>.Current = contextManager;
                        result = _channel.Do(Param);
                    }
                }
                else
                {
                    //理论上应该不会走到这里
                    result = _channel.Do(Param);
                    Debug.Assert(true, "服务 Agent里打开的Channel不是 IContextChannel 类型,神马情况?需要确认一下");
                }
                return result;
            }
            catch (FaultException<ServiceExceptionBase> seb)
            {
                //系统异常
                //TO DO Log...
                if (seb.Detail != null)
                    throw seb.Detail;
                else
                    throw new ServiceExceptionBase();
            }
            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();
                }
            }
        }