ConvertTransferException() static private method

The Channel layer normalizes exceptions thrown by the underlying networking implementations into subclasses of CommunicationException, so that Channels can be used polymorphically from an exception handling perspective.
static private ConvertTransferException ( SocketException socketException ) : System.ServiceModel.CommunicationException
socketException System.Net.Sockets.SocketException
return System.ServiceModel.CommunicationException
Esempio n. 1
0
            public SendAsyncResult(UdpOutputChannel channel, Message message, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel       = channel;
                this.messageBuffer = channel.EncodeMessage(message);
                try
                {
                    IAsyncResult result = null;
                    try
                    {
                        result = channel.socket.BeginSendTo(messageBuffer.Array, messageBuffer.Offset, messageBuffer.Count,
                                                            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. 2
0
        public void Send(Message message)
        {
            base.ThrowIfDisposedOrNotOpen();

            ArraySegment <byte> messageBuffer = EncodeMessage(message);

            // Adding the framing header
            messageBuffer = FramingCodec.Encode(this.remoteAddress.Uri,
                                                messageBuffer, parent.BufferManager);

            try
            {
                int bytesSent = this.socket.SendTo(messageBuffer.Array, messageBuffer.Offset, messageBuffer.Count,
                                                   SocketFlags.None, this.remoteEndPoint);

                if (bytesSent != messageBuffer.Count)
                {
                    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
            {
                // Must make sure buffers are always returned to the BufferManager
                parent.BufferManager.ReturnBuffer(messageBuffer.Array);
            }
        }
Esempio n. 3
0
        public void Send(Message message)
        {
            base.ThrowIfDisposedOrNotOpen();

            ArraySegment <byte> messageBuffer = EncodeMessage(message);

            byte[] httpHeaders = CreateHttpHeaders(messageBuffer.Count,
                                                   remoteAddress.Uri.AbsolutePath,
                                                   remoteAddress.Uri.Host);

            string headers = Encoding.UTF8.GetString(httpHeaders);

            byte[] bytes = new byte[httpHeaders.Length + messageBuffer.Count];

            Array.Copy(httpHeaders, bytes, httpHeaders.Length);

            Array.Copy(messageBuffer.Array, messageBuffer.Offset, bytes, httpHeaders.Length, messageBuffer.Count);

            string packet = Encoding.UTF8.GetString(bytes);

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\n--> Send:");
            Console.ResetColor();
            Console.WriteLine(packet);

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

                if (bytesSent != bytes.Length)
                {
                    throw new CommunicationException(string.Format(CultureInfo.CurrentCulture,
                                                                   "An error occurred sending a message to {0}.", this.remoteEndPoint));
                }
            }
            catch (SocketException socketException)
            {
                Console.WriteLine(socketException.Message);
                throw UdpChannelHelpers.ConvertTransferException(socketException);
            }
            finally
            {
                // we need to make sure buffers are always returned to the BufferManager
                parent.BufferManager.ReturnBuffer(messageBuffer.Array);
            }
        }
Esempio n. 4
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. 5
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);
            }
        }
Esempio n. 6
0
            void CompleteSend(IAsyncResult result, bool synchronous)
            {
                try
                {
                    int bytesSent = channel.socket.EndSendTo(result);

                    if (bytesSent != messageBuffer.Count)
                    {
                        throw new CommunicationException(string.Format(CultureInfo.CurrentCulture,
                                                                       "A Udp error occurred sending a message to {0}.", channel.remoteEndPoint));
                    }
                }
                catch (SocketException socketException)
                {
                    throw UdpChannelHelpers.ConvertTransferException(socketException);
                }
                finally
                {
                    CleanupBuffer();
                }

                base.Complete(synchronous);
            }