/// <summary> /// build response byte array /// </summary> /// <param name="operation">Client operation to response</param> /// <param name="message">Type of response</param> /// <param name="response">message to client</param> /// <returns></returns> public static byte[] ClientMessageBuild(ClientOperation operation, ClientMessage message, byte[] response) { using (var mem = new MemoryStream()) { var writer = new BinaryWriter(mem); writer.Write((byte)operation); writer.Write((Int32)message); if( response != null && response.Length > 0) { writer.Write(response); } writer.Flush(); return mem.ToArray(); } }
public static byte[] ClientMessageBuild(ClientOperation operation, ClientMessage message) { return ClientMessageBuild(operation, message, null); }
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) { }
private void InitializeFactories() { ISecurityCapabilities securityCapabilities = BootstrapSecurityBindingElement.GetProperty <ISecurityCapabilities>(IssuerBindingContext); SecurityCredentialsManager securityCredentials = IssuerBindingContext.BindingParameters.Find <SecurityCredentialsManager>(); if (securityCredentials == null) { securityCredentials = ClientCredentials.CreateDefaultCredentials(); } BindingContext context = IssuerBindingContext; _bootstrapSecurityBindingElement.ReaderQuotas = context.GetInnerProperty <XmlDictionaryReaderQuotas>(); if (_bootstrapSecurityBindingElement.ReaderQuotas == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.EncodingBindingElementDoesNotHandleReaderQuotas)); } TransportBindingElement transportBindingElement = context.RemainingBindingElements.Find <TransportBindingElement>(); if (transportBindingElement != null) { _bootstrapSecurityBindingElement.MaxReceivedMessageSize = transportBindingElement.MaxReceivedMessageSize; } SecurityProtocolFactory securityProtocolFactory = BootstrapSecurityBindingElement.CreateSecurityProtocolFactory <IRequestChannel>(IssuerBindingContext.Clone(), securityCredentials, false, IssuerBindingContext.Clone()); if (_localAddress != null) { MessageFilter issueAndRenewFilter = new SessionActionFilter(_standardsManager, IssueResponseAction.Value, RenewResponseAction.Value); context.BindingParameters.Add(new LocalAddressProvider(_localAddress, issueAndRenewFilter)); } ChannelBuilder channelBuilder = new ChannelBuilder(context, true); IChannelFactory innerChannelFactory; // if the underlying transport does not support request/reply, wrap it inside // a service channel factory. if (channelBuilder.CanBuildChannelFactory <IRequestChannel>()) { innerChannelFactory = channelBuilder.BuildChannelFactory <IRequestChannel>(); _requiresManualReplyAddressing = true; } else { ClientRuntime clientRuntime = new ClientRuntime("RequestSecuritySession", NamingHelper.DefaultNamespace); clientRuntime.UseSynchronizationContext = false; clientRuntime.AddTransactionFlowProperties = false; clientRuntime.ValidateMustUnderstand = false; ServiceChannelFactory serviceChannelFactory = ServiceChannelFactory.BuildChannelFactory(channelBuilder, clientRuntime); ClientOperation issueOperation = new ClientOperation(serviceChannelFactory.ClientRuntime, "Issue", IssueAction.Value); issueOperation.Formatter = s_operationFormatter; serviceChannelFactory.ClientRuntime.Operations.Add(issueOperation); ClientOperation renewOperation = new ClientOperation(serviceChannelFactory.ClientRuntime, "Renew", RenewAction.Value); renewOperation.Formatter = s_operationFormatter; serviceChannelFactory.ClientRuntime.Operations.Add(renewOperation); innerChannelFactory = new RequestChannelFactory(serviceChannelFactory); _requiresManualReplyAddressing = false; } SecurityChannelFactory <IAsyncRequestChannel> securityChannelFactory = new SecurityChannelFactory <IAsyncRequestChannel>( securityCapabilities, IssuerBindingContext, channelBuilder, securityProtocolFactory, innerChannelFactory); // attach the ExtendedProtectionPolicy to the securityProtcolFactory so it will be // available when building the channel. if (transportBindingElement != null) { if (securityChannelFactory.SecurityProtocolFactory != null) { securityChannelFactory.SecurityProtocolFactory.ExtendedProtectionPolicy = transportBindingElement.GetProperty <ExtendedProtectionPolicy>(context); } } _rstChannelFactory = securityChannelFactory; MessageVersion = securityChannelFactory.MessageVersion; }
public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation) { Console.WriteLine("IOperationBehavior - ApplyClientBehavior " + _host.ChannelDispatchers.Count); }
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 operation, ClientOperation client) { ; }
object Request(OperationDescription od, bool isAsync, ref object [] parameters, OperationContext context) { ClientOperation op = runtime.Operations [od.Name]; object [] inspections = new object [runtime.MessageInspectors.Count]; Message req = CreateRequest(op, parameters, context); for (int i = 0; i < inspections.Length; i++) { inspections [i] = runtime.MessageInspectors [i].BeforeSendRequest(ref req, this); } Message res = Request(req, OperationTimeout); if (res.IsFault) { var resb = res.CreateBufferedCopy(runtime.MaxFaultSize); MessageFault fault = MessageFault.CreateFault(resb.CreateMessage(), runtime.MaxFaultSize); var conv = OperationChannel.GetProperty <FaultConverter> () ?? FaultConverter.GetDefaultFaultConverter(res.Version); Exception ex; if (!conv.TryCreateException(resb.CreateMessage(), fault, out ex)) { if (fault.HasDetail) { Type detailType = typeof(ExceptionDetail); var freader = fault.GetReaderAtDetailContents(); DataContractSerializer ds = null; foreach (var fci in op.FaultContractInfos) { if (res.Headers.Action == fci.Action || fci.Serializer.IsStartObject(freader)) { detailType = fci.Detail; ds = fci.Serializer; break; } } if (ds == null) { ds = new DataContractSerializer(detailType); } var detail = ds.ReadObject(freader); ex = (Exception)Activator.CreateInstance(typeof(FaultException <>).MakeGenericType(detailType), new object [] { detail, fault.Reason, fault.Code, res.Headers.Action }); } if (ex == null) { ex = new FaultException(fault); } } throw ex; } for (int i = 0; i < inspections.Length; i++) { runtime.MessageInspectors [i].AfterReceiveReply(ref res, inspections [i]); } if (!op.DeserializeReply) { return(res); } if (isAsync && od.EndMethod != null) { var endParams = od.EndMethod.GetParameters(); parameters = new object [endParams.Length - 1]; } return(op.Formatter.DeserializeReply(res, parameters)); }
Message CreateRequest(ClientOperation op, object [] parameters, OperationContext context) { MessageVersion version = message_version; if (version == null) { version = MessageVersion.Default; } Message msg; if (op.SerializeRequest) { msg = op.Formatter.SerializeRequest( version, parameters); } else { if (parameters.Length != 1) { throw new ArgumentException(String.Format("Argument parameters does not match the expected input. It should contain only a Message, but has {0} parameters", parameters.Length)); } if (!(parameters [0] is Message)) { throw new ArgumentException(String.Format("Argument should be only a Message, but has {0}", parameters [0] != null ? parameters [0].GetType().FullName : "null")); } msg = (Message)parameters [0]; } context = context ?? OperationContext.Current; if (context != null) { // CopyHeadersFrom does not work here (brings duplicates -> error) foreach (var mh in context.OutgoingMessageHeaders) { int x = msg.Headers.FindHeader(mh.Name, mh.Namespace, mh.Actor); if (x >= 0) { msg.Headers.RemoveAt(x); } msg.Headers.Add((MessageHeader)mh); } msg.Properties.CopyProperties(context.OutgoingMessageProperties); } // FIXME: disabling MessageId as it's not seen for bug #567672 case. But might be required for PeerDuplexChannel. Check it later. //if (OutputSession != null) // msg.Headers.MessageId = new UniqueId (OutputSession.Id); msg.Properties.AllowOutputBatching = AllowOutputBatching; if (msg.Version.Addressing.Equals(AddressingVersion.WSAddressing10)) { if (msg.Headers.MessageId == null) { msg.Headers.MessageId = new UniqueId(); } if (msg.Headers.ReplyTo == null) { msg.Headers.ReplyTo = new EndpointAddress(Constants.WsaAnonymousUri); } if (msg.Headers.To == null && RemoteAddress != null) { msg.Headers.To = RemoteAddress.Uri; } } return(msg); }
void Output(OperationDescription od, object [] parameters, OperationContext context) { ClientOperation op = runtime.Operations [od.Name]; Send(CreateRequest(op, parameters, context), OperationTimeout); }
void IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy) { }
void IOperationBehavior.ApplyClientBehavior(OperationDescription operation, ClientOperation client) { // "it is a passive operation behavior" }
public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation) { clientOperation.ParameterInspectors.Add(this); }
public void ApplyClientBehavior(OperationDescription description, ClientOperation proxy) { return; }