Inheritance: IServiceMessage
示例#1
0
        /// <summary>
        /// Asynchronously calls the Publish service.
        /// </summary>
        public virtual IAsyncResult BeginPublish(PublishMessage message, AsyncCallback callback, object callbackData)
        {
            try
            {
                // check for bad data.
                if (message == null) throw new ArgumentNullException("message");

                // set the request context.
                SetRequestContext(RequestEncoding.Xml);

                // create handler.
                ProcessRequestAsyncResult result = new ProcessRequestAsyncResult(this, callback, callbackData, 0);
                return result.BeginProcessRequest(SecureChannelContext.Current, message.PublishRequest);
            }
            catch (Exception e)
            {
                throw CreateSoapFault(message.PublishRequest, e);
            }
        }
示例#2
0
        /// <summary>
        /// The operation contract for the Publish service.
        /// </summary>
        public virtual PublishResponseMessage Publish(PublishMessage request)
        {
            PublishResponse response = null;

            try
            {
                // OnRequestReceived(message.PublishRequest);

                SetRequestContext(RequestEncoding.Xml);
                response = (PublishResponse)Publish(request.PublishRequest);
                // OnResponseSent(response);
                return new PublishResponseMessage(response);
            }
            catch (Exception e)
            {
                Exception fault = CreateSoapFault(request.PublishRequest, e);
                // OnResponseFaultSent(fault);
                throw fault;
            }
        }
示例#3
0
 /// <summary>
 /// The operation contract for the Publish service.
 /// </summary>
 public virtual PublishResponseMessage Publish(PublishMessage request)
 {
     try
     {
         SetRequestContext(RequestEncoding.Xml);
         PublishResponse response = (PublishResponse)Publish(request.PublishRequest);
         return new PublishResponseMessage(response);
     }
     catch (Exception e)
     {
         throw CreateSoapFault(request.PublishRequest, e);
     }
 }
示例#4
0
        /// <summary>
        /// Tells the server that the client is ready to receive notifications from the server.
        /// </summary>
        public PublishResponseMessage Publish(PublishMessage request)
        {
            try
            {
                // validate the sesion
                Session session = VerifySession(request.RequestHeader, false);

                uint subscriptionId = 0;
                NotificationMessage message = null;

                QueuedRequest queuedRequest = new QueuedRequest();

                lock (m_messages)
                {
                    // first check if there are any messages waiting to be published.
                    for (LinkedListNode<QueuedMessage> node = m_messages.First; node != null; node = node.Next)
                    {
                        // ensure the message belongs to the current session
                        if (Object.ReferenceEquals(session, node.Value.Session))
                        {
                            // pull the message off the queue and return.
                            subscriptionId = node.Value.Subscription.Id;
                            message = node.Value.Message;
                            m_messages.Remove(node);
                            break;
                        }
                    }

                    // must process requests in the order that they arrive.
                    if (message == null)
                    {
                        queuedRequest.Session = session;
                        queuedRequest.Timeout = DateTime.UtcNow.AddMilliseconds(request.RequestHeader.TimeoutHint);
                        queuedRequest.Signal = new ManualResetEvent(false);
                        m_requests.AddLast(queuedRequest);
                    }
                }

                // wait for a notification.
                if (message == null)
                {
                    try
                    {
                        queuedRequest.Signal.WaitOne();

                        if (queuedRequest.Message == null)
                        {
                            throw new StatusCodeException(StatusCodes.BadTimeout, "Timed out waiting for notifications.");
                        }

                        subscriptionId = queuedRequest.SubscriptionId;
                        message = queuedRequest.Message;
                    }
                    finally
                    {
                        queuedRequest.Signal.Close();
                    }
                }

                // sent response.
                PublishResponseMessage response = new PublishResponseMessage();

                response.ResponseHeader = CreateResponseHeader(request.RequestHeader);
                response.SubscriptionId = subscriptionId;
                response.NotificationMessage = message;
                response.MoreNotifications = false;
                response.Results = new ListOfStatusCode();
                response.DiagnosticInfos = new ListOfDiagnosticInfo();
                response.AvailableSequenceNumbers = new ListOfUInt32();

                return response;
            }
            catch (Exception e)
            {
                throw CreateSoapFault(request.RequestHeader, e);
            }
        }