public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
        {
            var serializer = JsonSerializer.Create(settingsProvider());

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                    using (var jsonWriter = new JsonTextWriter(writer))
                    {
                        jsonWriter.WriteStartObject();
                        foreach (var part in operationParameters)
                        {
                            object paramValue = parameters[part.Index];

                            if (paramValue != null)
                            {
                                jsonWriter.WritePropertyName(part.Name);
                                serializer.Serialize(jsonWriter, paramValue);
                            }
                        }

                        jsonWriter.WriteEndObject();
                    }

                var message = MessageBinaryHelper.SerializeMessage(stream.ToArray());

                message.Properties[SolaceConstants.ApplicationMessageTypeKey] = applicationMessageType;
                message.Properties[SolaceConstants.CorrelationIdKey]          = new RequestCorrelationState();

                return(message);
            }
        }
        public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result)
        {
            var message = MessageBinaryHelper.SerializeMessage(Converter.SerializeReply(result));

            message.Properties["ApplicationMessageType"] = ReplyApplicationMessageType;

            return(message);
        }
        public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result)
        {
            var reply = MessageBinaryHelper.SerializeMessage(Serialize(result));

            reply.Properties[SolaceConstants.ApplicationMessageTypeKey] = replyApplicationMessageType;

            return(reply);
        }
 private static JsonTextReader GetJsonReaderAtMessageBody(Message message) =>
 message.Properties.TryGetValue(SolaceConstants.ReplyReaderKey, out object reader)
         ? (JsonTextReader)reader
         : new JsonTextReader(
     new StreamReader(
         new MemoryStream(MessageBinaryHelper.ReadMessageBinary(message))))
 {
     CloseInput = true
 };
Exemple #5
0
        protected static byte[] ReadMessageBinaryHelper(Message message)
        {
            var array = MessageBinaryHelper.ReadMessageBinary(message);

            if (!array.SequenceEqual(empty))
            {
                return(array);
            }

            return(new byte[0]);
        }
Exemple #6
0
 public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
 {
     clientRuntime.MessageInspectors.Add(new SolaceMessageInspector());
     foreach (OperationDescription operation in endpoint.Contract.Operations)
     {
         if (!MessageBinaryHelper.IsUntypedMessage(operation))
         {
             ClientOperation clientOperation = clientRuntime.Operations[operation.Name];
             clientOperation.SerializeRequest = true;
             clientOperation.DeserializeReply = true;
             clientOperation.Formatter        = new SolaceMessageFormatter(operation, settingsProvider);
         }
     }
 }
        public virtual void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
            clientRuntime.MessageInspectors.Add(new SolaceMessageInspector());

            foreach (var operationDescription in endpoint.Contract.Operations)
            {
                if (!MessageBinaryHelper.IsUntypedMessage(operationDescription))
                {
                    var clientOperation = clientRuntime.Operations[operationDescription.Name];

                    clientOperation.SerializeRequest = true;
                    clientOperation.DeserializeReply = true;
                    clientOperation.Formatter        = new SolaceSdtStreamContainerMessageFormatter(operationDescription);
                }
            }
        }
        public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
        {
            var message = MessageBinaryHelper.SerializeMessage(
                binaryParameterIndex != null
                    ? (byte[])parameters[binaryParameterIndex.Value]
                    : null);

            message.Properties["ApplicationMessageType"] = ApplicationMessageType;
            message.Properties["CorrelationId"]          = new RequestCorrelationState();

            if (IsOneWay)
            {
                message.Properties["IsOneWay"] = true;
            }

            return(message);
        }
        public virtual void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            endpointDispatcher.ContractFilter = new MatchAllMessageFilter();
            endpointDispatcher.DispatchRuntime.OperationSelector = new SolaceOperationSelector();
            endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new SolaceMessageInspector());

            foreach (var operationDescription in endpoint.Contract.Operations)
            {
                if (!MessageBinaryHelper.IsUntypedMessage(operationDescription))
                {
                    var dispatchOperation = endpointDispatcher.DispatchRuntime.Operations[operationDescription.Name];

                    dispatchOperation.DeserializeRequest = true;
                    dispatchOperation.SerializeReply     = true;
                    dispatchOperation.Formatter          = new SolaceSdtStreamContainerMessageFormatter(operationDescription);
                }
            }
        }
Exemple #10
0
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new SolaceMessageInspector());
     endpointDispatcher.DispatchRuntime.OperationSelector = new SolaceOperationSelector();
     endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(new SolaceJsonErrorHandler());
     endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(new SolaceJsonPassthroughErrorHandler());
     endpointDispatcher.ContractFilter = new MatchAllMessageFilter();
     foreach (OperationDescription operation in endpoint.Contract.Operations)
     {
         if (!MessageBinaryHelper.IsUntypedMessage(operation))
         {
             DispatchOperation dispatchOperation = endpointDispatcher.DispatchRuntime.Operations[operation.Name];
             dispatchOperation.DeserializeRequest = true;
             dispatchOperation.SerializeReply     = true;
             dispatchOperation.Formatter          = new SolaceMessageFormatter(operation, settingsProvider);
         }
     }
 }
        public virtual void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            endpointDispatcher.ContractFilter = new MatchAllMessageFilter();
            endpointDispatcher.DispatchRuntime.OperationSelector = new SolaceOperationSelector();
            endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new SolaceMessageInspector());
            endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(new SolaceProtobufErrorHandler());

            foreach (var operation in endpoint.Contract.Operations)
            {
                if (!MessageBinaryHelper.IsUntypedMessage(operation))
                {
                    var dispatchOperation = endpointDispatcher.DispatchRuntime.Operations[operation.Name];

                    dispatchOperation.DeserializeRequest = true;
                    dispatchOperation.SerializeReply     = true;
                    dispatchOperation.Formatter          = new SolaceProtobufMessageFormatter(operation, converterFactory);
                }
            }
        }
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            if (HandleError(error))
            {
                Message message;

                using (var stream = new MemoryStream())
                {
                    WriteException(error, stream,
                                   fault?.Properties[SolaceConstants.ApplicationMessageTypeKey].ToString());
                    message = MessageBinaryHelper.SerializeMessage(stream.ToArray());
                }

                if (fault != null)
                {
                    message.Properties.CopyProperties(fault.Properties);
                    message.Headers.CopyHeadersFrom(fault.Headers);
                    fault.Close();
                }

                message.Properties[SolaceConstants.ApplicationMessageTypeKey] = "Fault";
                fault = message;
            }
        }
        public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
        {
            var message = MessageBinaryHelper.SerializeMessage(Converter.SerializeRequest(parameters));

            if (senderIdIndex != null)
            {
                object obj = parameters[senderIdIndex.Value];

                if (obj != null)
                {
                    message.Properties["SenderId"] = obj;
                }
            }

            message.Properties["ApplicationMessageType"] = ApplicationMessageType;
            message.Properties["CorrelationId"]          = new RequestCorrelationState();

            if (IsOneWay)
            {
                message.Properties["IsOneWay"] = true;
            }

            return(message);
        }