public void ApplyClientBehavior(OperationDescription operationDescription,
                                 System.ServiceModel.Dispatcher.ClientOperation clientOperation)
 {
     // If this is applied on the client, well, it just doesn’t make sense.
     // Don’t throw in case this attribute was applied on the contract
     // instead of the implementation.
 }
        public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
        {
            Console.WriteLine("{0}: ", clientOperation.Name);
            IClientMessageFormatter formatter = clientOperation.Formatter;
            Console.WriteLine("\t{0}", formatter.GetType().Name);

            if (formatter.GetType().Name != "CompositeClientFormatter")
            {
            return;
            }

            object innerFormatter = this.GetField(formatter, "request");
            Console.WriteLine("\t\t{0}", innerFormatter.GetType().Name);

            if (innerFormatter.GetType().Name == "UriTemplateClientFormatter")
            {
            innerFormatter = this.GetField(innerFormatter, "inner");
            Console.WriteLine("\t\t\t{0}", innerFormatter.GetType().Name);
            return;
            }

            if (innerFormatter.GetType().Name == "ContentTypeSettingClientMessageFormatter")
            {
            innerFormatter = this.GetField(innerFormatter, "innerFormatter");
            Console.WriteLine("\t\t\t{0}", innerFormatter.GetType().Name);

            if (innerFormatter.GetType().Name == "UriTemplateClientFormatter")
            {
                innerFormatter = this.GetField(innerFormatter, "inner");
                Console.WriteLine("\t\t\t\t{0}", innerFormatter.GetType().Name);
            }
            }
        }
 void IOperationBehavior.ApplyClientBehavior(OperationDescription operationDescription, 
     ClientOperation clientOperation) 
 {
     ZipCodeInspector zipCodeInspector = new ZipCodeInspector(); 
     
     clientOperation.ParameterInspectors.Add(zipCodeInspector); 
 }
 public void ApplyClientBehavior(OperationDescription description, ClientOperation proxy)
 {
     var dataContractSerializerOperationBehavior =
         description.Behaviors.Find<DataContractSerializerOperationBehavior>();
     dataContractSerializerOperationBehavior.DataContractResolver =
         new ProxyDataContractResolver();
 }
Example #5
0
 public void ApplyClientBehavior(OperationDescription description,
     ClientOperation proxy)
 {
     IOperationBehavior innerBehavior =
       new ReferencePreservingDataContractSerializerOperationBehavior(description);
     innerBehavior.ApplyClientBehavior(description, proxy);
 }
 public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
 {
     clientOperation.Formatter = new RestClientMessageFormatter(clientOperation.Formatter
         , operationDescription
         , this.Mapper
         , this.Configuration);
 }
 public void ApplyClientBehavior(OperationDescription description, ClientOperation runtime)
 {
     if (_runtime == runtime.Parent)
     {
         //在之前的创建的 Formatter 的基础上,装饰新的 Formatter
         runtime.Formatter = new BinaryFormatterAdapter(description.Name, runtime.SyncMethod.GetParameters(), runtime.Formatter, runtime.Action);
     }
 }
        /// <summary>
        /// Apply the client behavior by requiring
        /// the use of the NetDataContractSerializer.
        /// </summary>
        /// <param name="description">Operation description.</param>
        /// <param name="proxy">Client operation object.</param>
        public void ApplyClientBehavior(OperationDescription description, ClientOperation proxy)
        {
            description.Behaviors.Remove<DataContractSerializerOperationBehavior>();

            //直接让行为起作用,否则优先级的效果会不对。
            IOperationBehavior ndcob = new NetDataContractOperationBehavior(description);
            ndcob.ApplyClientBehavior(description, proxy);
            //description.Behaviors.Add(new NetDataContractOperationBehavior(description));
        }
 internal static IClientMessageFormatter GetFormatterFromRuntime(OperationDescription operationDescription)
 {
     ClientOperation clientOperation = new ClientOperation(DummyClientRuntime, operationDescription.Name, operationDescription.Messages[0].Action);
     foreach (IOperationBehavior behavior in operationDescription.Behaviors)
     {
         behavior.ApplyClientBehavior(operationDescription, clientOperation);
     }
     return clientOperation.Formatter;
 }
Example #10
0
    public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
    {
        foreach (ClientOperation clientOperation in clientRuntime.ClientOperations)
        {
            if (clientOperation.Name == "TestFaultWithKnownType")
            {
                testFaultWithKnownTypeClientOp = clientOperation;
                return;
            }
        }

        throw new Exception("Expected TestFaultWithKnownType in the ClientOperations, Actual:  TestFaultWithKnownType NOT Found");
    }
        public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
        {
            clientOperation.SerializeRequest = true;
            clientOperation.DeserializeReply = true;
            var dataContractFormatAttribute = operationDescription.SyncMethod.GetCustomAttributes(typeof(DataContractFormatAttribute), true).FirstOrDefault() as DataContractFormatAttribute;
            if (null == dataContractFormatAttribute)
            {
                dataContractFormatAttribute = new DataContractFormatAttribute();
            }

            var dataContractSerializerOperationBehavior = operationDescription.Behaviors.Find<DataContractSerializerOperationBehavior>();
            clientOperation.Formatter = new CompressionMessageFormatter(this.Algorithm, operationDescription, dataContractFormatAttribute, dataContractSerializerOperationBehavior);
        }
        internal ProxyOperationRuntime(ClientOperation operation, ImmutableClientRuntime parent)
        {
            if (operation == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operation");
            if (parent == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("parent");

            this.parent = parent;
            this.formatter = operation.Formatter;
            this.isInitiating = operation.IsInitiating;
            this.isOneWay = operation.IsOneWay;
            this.isTerminating = operation.IsTerminating;
            this.isSessionOpenNotificationEnabled = operation.IsSessionOpenNotificationEnabled;
            this.name = operation.Name;
            this.parameterInspectors = EmptyArray<IParameterInspector>.ToArray(operation.ParameterInspectors);
            this.faultFormatter = operation.FaultFormatter;
            this.serializeRequest = operation.SerializeRequest;
            this.deserializeReply = operation.DeserializeReply;
            this.action = operation.Action;
            this.replyAction = operation.ReplyAction;
            this.beginMethod = operation.BeginMethod;
            this.syncMethod = operation.SyncMethod;
            this.taskMethod = operation.TaskMethod;
            this.TaskTResult = operation.TaskTResult;

            if (this.beginMethod != null)
            {
                this.inParams = ServiceReflector.GetInputParameters(this.beginMethod, true);
                if (this.syncMethod != null)
                {
                    this.outParams = ServiceReflector.GetOutputParameters(this.syncMethod, false);
                }
                else
                {
                    this.outParams = NoParams;
                }
                this.endOutParams = ServiceReflector.GetOutputParameters(operation.EndMethod, true);
                this.returnParam = operation.EndMethod.ReturnParameter;
            }
            else if (this.syncMethod != null)
            {
                this.inParams = ServiceReflector.GetInputParameters(this.syncMethod, false);
                this.outParams = ServiceReflector.GetOutputParameters(this.syncMethod, false);
                this.returnParam = this.syncMethod.ReturnParameter;
            }

            if (this.formatter == null && (serializeRequest || deserializeReply))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ClientRuntimeRequiresFormatter0, this.name)));
            }
        }
Example #13
0
        internal ProxyOperationRuntime(ClientOperation operation, ImmutableClientRuntime parent)
        {
            if (operation == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operation");
            if (parent == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("parent");

            _parent = parent;
            _formatter = operation.Formatter;
            _isInitiating = operation.IsInitiating;
            _isOneWay = operation.IsOneWay;
            _isTerminating = operation.IsTerminating;
            _isSessionOpenNotificationEnabled = operation.IsSessionOpenNotificationEnabled;
            _name = operation.Name;
            _parameterInspectors = EmptyArray<IParameterInspector>.ToArray(operation.ParameterInspectors);
            _faultFormatter = operation.FaultFormatter;
            _serializeRequest = operation.SerializeRequest;
            _deserializeReply = operation.DeserializeReply;
            _action = operation.Action;
            _replyAction = operation.ReplyAction;
            _beginMethod = operation.BeginMethod;
            _syncMethod = operation.SyncMethod;
            _taskMethod = operation.TaskMethod;
            this.TaskTResult = operation.TaskTResult;

            if (_beginMethod != null)
            {
                _inParams = ServiceReflector.GetInputParameters(_beginMethod, true);
                if (_syncMethod != null)
                {
                    _outParams = ServiceReflector.GetOutputParameters(_syncMethod, false);
                }
                else
                {
                    _outParams = Array.Empty<ParameterInfo>();
                }
                _endOutParams = ServiceReflector.GetOutputParameters(operation.EndMethod, true);
                _returnParam = operation.EndMethod.ReturnParameter;
            }
            else if (_syncMethod != null)
            {
                _inParams = ServiceReflector.GetInputParameters(_syncMethod, false);
                _outParams = ServiceReflector.GetOutputParameters(_syncMethod, false);
                _returnParam = _syncMethod.ReturnParameter;
            }

            if (_formatter == null && (_serializeRequest || _deserializeReply))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.ClientRuntimeRequiresFormatter0, _name)));
            }
        }
 void IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy)
 {
     if (description == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description");
     }
     if (proxy == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("proxy");
     }
     if (proxy.Formatter == null)
     {
         bool flag;
         bool flag2;
         proxy.Formatter = (IClientMessageFormatter) this.GetFormatter(description, out flag, out flag2, true);
         proxy.SerializeRequest = flag;
         proxy.DeserializeReply = flag2;
     }
 }
        public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
        {
            Console.WriteLine("{0}: ", clientOperation.Name);
            IClientMessageFormatter formatter = clientOperation.Formatter;
            Console.WriteLine("\t{0}", formatter.GetType().Name);

            if (formatter.GetType().Name != "CompositeClientFormatter")
            {
            return;
            }
            object innerFormatter = this.GetField(formatter, "reply");
            Console.WriteLine("\t\t{0}", innerFormatter.GetType().Name);

            if (innerFormatter.GetType().Name == "DemultiplexingClientMessageFormatter")
            {
            Dictionary<WebContentFormat, IClientMessageFormatter> formatters = this.GetField(innerFormatter,"formatters") as Dictionary<WebContentFormat, IClientMessageFormatter>;
            Console.WriteLine("\t\t\t{0, -4}: {1}", "Xml", formatters[WebContentFormat.Xml].GetType().Name);
            Console.WriteLine("\t\t\t{0, -4}: {1}", "Json", formatters[WebContentFormat.Json].GetType().Name);
            }
        }
        internal static IClientMessageFormatter GetFormatterFromRuntime(OperationDescription operationDescription)
        {
            System.ServiceModel.Dispatcher.ClientOperation clientOperation = new System.ServiceModel.Dispatcher.ClientOperation(DummyClientRuntime, operationDescription.Name, operationDescription.Messages[0].Action);

            // Default to DataContractSerializerOperationBehavior
            if (operationDescription.Behaviors.Count == 0)
            {
                IOperationBehavior operationBehavior = new DataContractSerializerOperationBehavior(operationDescription);
                operationBehavior.ApplyClientBehavior(operationDescription, clientOperation);
            }
            else
            {
                foreach (IOperationBehavior operationBehavior in operationDescription.Behaviors)
                {
                    operationBehavior.ApplyClientBehavior(operationDescription, clientOperation);
                }
            }

            return clientOperation.Formatter;
        }
        internal static IClientMessageFormatter GetFormatterFromRuntime(OperationDescription operationDescription)
        {
            System.ServiceModel.Dispatcher.ClientOperation clientOperation = new System.ServiceModel.Dispatcher.ClientOperation(DummyClientRuntime, operationDescription.Name, operationDescription.Messages[0].Action);

            // Default to DataContractSerializerOperationBehavior
            if (operationDescription.Behaviors.Count == 0)
            {
                IOperationBehavior operationBehavior = new DataContractSerializerOperationBehavior(operationDescription);
                operationBehavior.ApplyClientBehavior(operationDescription, clientOperation);
            }
            else
            {
                foreach (IOperationBehavior operationBehavior in operationDescription.Behaviors)
                {
                    operationBehavior.ApplyClientBehavior(operationDescription, clientOperation);
                }
            }

            return(clientOperation.Formatter);
        }
		void IOperationBehavior.ApplyClientBehavior (
			OperationDescription description,
			ClientOperation proxy)
		{
			if (description == null)
				throw new ArgumentNullException ("description");
			if (proxy == null)
				throw new ArgumentNullException ("proxy");
			proxy.Formatter = new XmlMessagesFormatter (description, format);
		}
        void IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy)
        {
            if (description == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description");

            if (proxy == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("proxy");

            if (proxy.Formatter == null)
            {
                proxy.Formatter = (IClientMessageFormatter)CreateFormatter();
                proxy.SerializeRequest = _reflector.RequestRequiresSerialization;
                proxy.DeserializeReply = _reflector.ReplyRequiresSerialization;
            }

            if (_reflector.Attribute.SupportFaults && !proxy.IsFaultFormatterSetExplicit)
                proxy.FaultFormatter = (IClientFaultFormatter)CreateFaultFormatter(proxy.FaultContractInfos);
        }
 void IOperationBehavior.ApplyClientBehavior(OperationDescription operationDescription, System.ServiceModel.Dispatcher.ClientOperation clientOperation)
 {
 }
Example #21
0
 public void ApplyClientBehavior(OperationDescription operationDescription, System.ServiceModel.Dispatcher.ClientOperation clientOperation)
 {
     //throw new NotImplementedException();
 }
Example #22
0
        private static void BuildProxyOperation(OperationDescription operation, ClientRuntime parent)
        {
            ClientOperation child;
            if (operation.Messages.Count == 1)
            {
                child = new ClientOperation(parent, operation.Name, operation.Messages[0].Action);
            }
            else
            {
                child = new ClientOperation(parent, operation.Name, operation.Messages[0].Action,
                                            operation.Messages[1].Action);
            }
            child.TaskMethod = operation.TaskMethod;
            child.TaskTResult = operation.TaskTResult;
            child.SyncMethod = operation.SyncMethod;
            child.BeginMethod = operation.BeginMethod;
            child.EndMethod = operation.EndMethod;
            child.IsOneWay = operation.IsOneWay;
            child.IsTerminating = operation.IsTerminating;
            child.IsInitiating = operation.IsInitiating;
            child.IsSessionOpenNotificationEnabled = operation.IsSessionOpenNotificationEnabled;
            for (int i = 0; i < operation.Faults.Count; i++)
            {
                FaultDescription fault = operation.Faults[i];
                child.FaultContractInfos.Add(new FaultContractInfo(fault.Action, fault.DetailType, fault.ElementName, fault.Namespace, operation.KnownTypes));
            }

            parent.Operations.Add(child);
        }
 void IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy)
 {
 }
Example #24
0
 void IOperationBehavior.ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
 {
 }
		void IOperationBehavior.ApplyClientBehavior (OperationDescription operation, ClientOperation client)
		{
			// "it is a passive operation behavior"
		}
 public void ApplyClientBehavior(OperationDescription operationDescription, System.ServiceModel.Dispatcher.ClientOperation clientOperation)
 {
     // Set the default serializer to the customized serialization
     clientOperation.Formatter = new DecompressionMessageFormatter(clientOperation.Formatter, operationDescription.SyncMethod.ReturnType);
 }
Example #27
0
 public void ApplyClientBehavior(OperationDescription operationDescription, 
     ClientOperation clientOperation)
 {
 }
Example #28
0
 public void ApplyClientBehavior(OperationDescription operationDescription, System.ServiceModel.Dispatcher.ClientOperation clientOperation)
 {
     clientOperation.Parent.MessageInspectors.Add(new HeaderContextClientMessageInspector(m_IsWebHttpBinding));
 }
Example #29
0
    public void ApplyClientBehavior(OperationDescription description, System.ServiceModel.Dispatcher.ClientOperation proxy)
    {
        IOperationBehavior innerBehavior = new ReferencePreservingDataContractSerializerOperationBehavior(description);

        innerBehavior.ApplyClientBehavior(description, proxy);
    }
		void IOperationBehavior.ApplyClientBehavior (
			OperationDescription description,
			ClientOperation proxy)
		{
			proxy.Formatter = new DataContractMessagesFormatter (description, format);
		}
		void IOperationBehavior.ApplyClientBehavior (
			OperationDescription description,
			ClientOperation proxy)
		{
			//throw new NotImplementedException ();
		}
 public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
 {
     clientOperation.ParameterInspectors.Add(new Inspector());
 }
 public void ApplyClientBehavior(OperationDescription description, ClientOperation runtime)
 {
     if (innerFormatterBehavior != null && runtime.Formatter == null)
     {
         // no formatter has been applied yet
         innerFormatterBehavior.ApplyClientBehavior(description, runtime);
     }
     runtime.Formatter = new QueryStringFormatter(description.Name, runtime.SyncMethod.GetParameters(), runtime.Formatter, runtime.Action, endpointAddress);
 }
        void IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy)
        {
            if (description == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description");

            if (proxy == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("proxy");

            if (proxy.Formatter != null)
                return;

            bool formatRequest;
            bool formatReply;
            proxy.Formatter = (IClientMessageFormatter)GetFormatter(description, out formatRequest, out formatReply, true);
            proxy.SerializeRequest = formatRequest;
            proxy.DeserializeReply = formatReply;
        }
 public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
 {
     m_OperationBehavior.ApplyClientBehavior(operationDescription, clientOperation);
 }
Example #36
0
 public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
 {
     throw new NotSupportedException();
 }
Example #37
0
 public void ApplyClientBehavior(OperationDescription description,
                                 System.ServiceModel.Dispatcher.ClientOperation proxy)
 {
     ReplaceDataContractSerializerOperationBehavior(description);
 }
 void IOperationBehavior.ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
 {
     IOperationBehavior innerBehavior = new ProtoOperationBehavior(operationDescription);
     innerBehavior.ApplyClientBehavior(operationDescription, clientOperation);
 }
    public void ApplyClientBehavior(OperationDescription description, System.ServiceModel.Dispatcher.ClientOperation proxy)
    {
        DataContractSerializerOperationBehavior dataContractSerializerOperationBehavior = description.Behaviors.Find <DataContractSerializerOperationBehavior>();

        dataContractSerializerOperationBehavior.DataContractResolver = new ProxyDataContractResolver();
    }
Example #40
0
 public void ApplyClientBehavior(OperationDescription operationDescription, System.ServiceModel.Dispatcher.ClientOperation clientOperation)
 {
     throw FxTrace.Exception.AsError(new NotImplementedException());
 }
Example #41
0
 void IOperationBehavior.ApplyClientBehavior(OperationDescription operationDescription, System.ServiceModel.Dispatcher.ClientOperation clientOperation)
 {
     CyclicReferencesAwareContractBehavior.ReplaceDataContractSerializerOperationBehavior(operationDescription, On);
 }