Esempio n. 1
0
        public static void Set(byte[] propToken, Message message)
        {
            if (message.Properties.ContainsKey(PropertyName))
            {
                throw new CommunicationException("A transaction flow property is already set on the message.");
            }

            TransactionFlowProperty property = new TransactionFlowProperty();

            property.propToken = propToken;
            message.Properties.Add(PropertyName, property);
        }
Esempio n. 2
0
        public static byte[] Get(Message message)
        {
            if (message == null)
            {
                return(null);
            }

            if (message.Properties.ContainsKey(PropertyName))
            {
                TransactionFlowProperty tfp = (TransactionFlowProperty)message.Properties[PropertyName];
                return(tfp.propToken);
            }

            return(null);
        }
Esempio n. 3
0
            public SendAsyncResult(UdpOutputChannel channel, Message message, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel = channel;

                //obtain the transaction propagation token from the TransactionFlowProperty on the message
                byte[] txPropToken = TransactionFlowProperty.Get(message);

                this.messageBuffer = channel.EncodeMessage(message);

                txmsgBuffer = TransactionMessageBuffer.WriteTransactionMessageBuffer(txPropToken, messageBuffer);
                if ((long)txmsgBuffer.Length > channel.Factory.MaxPacketSize)
                {
                    throw new CommunicationException("The output packet size is greater than the maximum size supported.");
                }

                try
                {
                    IAsyncResult result = null;
                    try
                    {
                        result = channel.socket.BeginSendTo(txmsgBuffer, 0, txmsgBuffer.Length,
                                                            SocketFlags.None, channel.remoteEndPoint, new AsyncCallback(OnSend), this);
                    }
                    catch (SocketException socketException)
                    {
                        throw UdpChannelHelpers.ConvertTransferException(socketException);
                    }

                    if (!result.CompletedSynchronously)
                    {
                        return;
                    }

                    CompleteSend(result, true);
                }
                catch
                {
                    CleanupBuffer();
                    throw;
                }
            }
Esempio n. 4
0
        public void Send(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            base.ThrowIfDisposedOrNotOpen();

            //obtain the transaction propagation token from the TransactionFlowProperty on the message
            byte[] txPropToken = TransactionFlowProperty.Get(message);

            ArraySegment <byte> messageBuffer = EncodeMessage(message);

            byte[] txmsgBuffer = TransactionMessageBuffer.WriteTransactionMessageBuffer(txPropToken, messageBuffer);
            if ((long)txmsgBuffer.Length > this.Factory.MaxPacketSize)
            {
                throw new CommunicationException("The output packet size is greater than the maximum size supported.");
            }

            try
            {
                int bytesSent = this.socket.SendTo(txmsgBuffer, 0, txmsgBuffer.Length,
                                                   SocketFlags.None, this.remoteEndPoint);

                if (bytesSent != txmsgBuffer.Length)
                {
                    throw new CommunicationException(string.Format(CultureInfo.CurrentCulture,
                                                                   "A Udp error occurred sending a message to {0}.", this.remoteEndPoint));
                }
            }
            catch (SocketException socketException)
            {
                throw UdpChannelHelpers.ConvertTransferException(socketException);
            }
            finally
            {
                // we need to make sure buffers are always returned to the BufferManager
                parent.BufferManager.ReturnBuffer(messageBuffer.Array);
            }
        }
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            // obtain the tx propagation token
            byte[] propToken = null;
            if (Transaction.Current != null && IsTxFlowRequiredForThisOperation(request.Headers.Action))
            {
                try
                {
                    propToken = TransactionInterop.GetTransmitterPropagationToken(Transaction.Current);
                }
                catch (TransactionException e)
                {
                    throw new CommunicationException("TransactionInterop.GetTransmitterPropagationToken failed.", e);
                }
            }

            // set the propToken on the message in a TransactionFlowProperty
            TransactionFlowProperty.Set(propToken, request);

            return(null);
        }