示例#1
0
        private Message invokeContract(IRpcCallInfo call, MessageRequest request, Type contractType)
        {
            OperationDispatchBase operation;
            bool operationExists = _operations.IdToOperation.TryGetValue(request.Operation, out operation);

            if (!operationExists)
            {
                var error        = new ActionNotSupportedException(string.Format("Server endpoint {0} with contract {1} does not supports operation with id = {2}. Check that client and server use the same version of contract and binding. ", _endpoint._address, contractType, request.Operation));
                var faultMessage = new Message();
                faultMessage = makeFault(error, faultMessage);
                return(faultMessage);
            }
            OperationContext operationContext = SetupOperationConext(call, request, contractType);
            Func <Message>   invokeAction     = () =>
            {
                OperationContext.Current = operationContext;
                if (_concurrency == ConcurrencyMode.Single)
                {
                    lock (this)
                    {
                        return(invokeContract(operation, request));
                    }
                }
                return(invokeContract(operation, request));
            };

            if (operation.Operation.IsOneWay)
            {
                Task task = Tasks.Factory.StartNew(invokeAction);
                task.ContinueWith(x => RpcTrace.Error(x.Exception), TaskContinuationOptions.OnlyOnFaulted);
                return(new Message());
            }
            else
            {
                return(invokeAction());
            }
        }
 private Message invokeContract(IRpcCallInfo call, MessageRequest request, Type contractType)
 {
     OperationDispatchBase operation;
     bool operationExists = _operations.IdToOperation.TryGetValue(request.Operation, out operation);
     if (!operationExists)
     {
         var error = new ActionNotSupportedException(string.Format("Server endpoint {0} with contract {1} does not supports operation with id = {2}. Check that client and server use the same version of contract and binding. ", _endpoint._address, contractType, request.Operation));
         var faultMessage = new Message();
         faultMessage = makeFault(error, faultMessage);
         return faultMessage;
     }
     OperationContext operationContext = SetupOperationConext(call, request, contractType);
     Func<Message> invokeAction = () =>
         {
             OperationContext.Current = operationContext;
             if (_concurrency == ConcurrencyMode.Single)
             {
                 lock (this)
                 {
                     return invokeContract(operation, request);
                 }
             }
             return invokeContract(operation, request);
         };
     if (operation.Operation.IsOneWay)
     {
         Task task = Tasks.Factory.StartNew(invokeAction);
         task.ContinueWith(x => RpcTrace.Error(x.Exception), TaskContinuationOptions.OnlyOnFaulted);
         return new Message();
     }
     else
     {
         return invokeAction();
     }
 }