Opc.Ua.Bindings.TcpServerChannel.SendResponse C# (CSharp) Method

SendResponse() public method

Sends the response for the specified request.
public SendResponse ( uint requestId, IServiceResponse response ) : void
requestId uint
response IServiceResponse
return void
        public void SendResponse(uint requestId, IServiceResponse response)
        {
            if (response == null) throw new ArgumentNullException("response");

            lock (DataLock)
            {
                // must queue the response if the channel is in the faulted state.
                if (State == TcpChannelState.Faulted)
                {
                    m_queuedResponses[requestId] = response;
                    return;
                }
                
                // Utils.Trace("Channel {0}: SendResponse {1}", ChannelId, requestId);
                
                BufferCollection buffers = null;

                try
                {
                    // note that the server does nothing if the message limits are exceeded.
                    bool limitsExceeded = false;

                    buffers = WriteSymmetricMessage(
                        TcpMessageType.Message,
                        requestId,
                        CurrentToken,
                        response,
                        false,
                        out limitsExceeded);
                }
                catch (Exception e)
                {     
                    SendServiceFault(
                        CurrentToken, 
                        requestId, 
                        ServiceResult.Create(e, StatusCodes.BadEncodingError, "Could not encode outgoing message."));
                    
                    return;
                }

                try
                {
                    BeginWriteMessage(buffers, Int32.MaxValue, null);
                    buffers = null;
                }
                catch (Exception)
                {
                    if (buffers != null)
                    {
                        buffers.Release(BufferManager, "SendResponse");
                    }

                    m_queuedResponses[requestId] = response;
                    return;
                }
            }
        }
        #endregion

Usage Example

コード例 #1
0
        private void OnProcessRequestComplete(IAsyncResult result)
        {
            if (m_callback != null)
            {
                try {
                    object[] args = (object[])result.AsyncState;

                    TcpServerChannel channel  = (TcpServerChannel)args[0];
                    IServiceResponse response = m_callback.EndProcessRequest(result);
                    channel.SendResponse((uint)args[1], response);
                } catch (Exception e) {
                    Utils.Trace(e, "TCPLISTENER - Unexpected error sending result.");
                }
            }
        }