Esempio n. 1
0
        /// <summary>
        /// HttpServer Socket Listener
        /// </summary>
        public void Listen()
        {
            // Create listener and start listening
            while (m_isStarted)
            {
                try
                {
                    _Bind.RequestContext context = m_replyChannel.ReceiveRequest();

                    // The context returned by m_httpListener.GetContext(); can be null in case the service was stopped.
                    if (context != null)
                    {
                        WsHttpMessageProcessor processor = new WsHttpMessageProcessor(m_serviceEndpoints);

                        // Try to get a processing thread and process the request
                        m_threadManager.StartNewThread(processor, context);
                        m_ctx.ContextObject = context.m_context.ContextObject;
                    }
                }
                catch
                {
                    m_ctx.ContextObject = null;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// HttpServer Socket Listener
        /// </summary>
        public void Listen()
        {
            // Create listener and start listening
            while (m_isStarted)
            {
                try
                {
                    _Bind.RequestContext context = m_replyChannel.ReceiveRequest();

                    // The context returned by m_httpListener.GetContext(); can be null in case the service was stopped.
                    if (context != null)
                    {
                        WsHttpMessageProcessor processor = new WsHttpMessageProcessor(m_serviceEndpoints, context);

                        if (m_threadManager.ThreadsAvailable == false)
                        {
                            WsWsaHeader header = new WsWsaHeader();

                            context.Reply(WsFault.GenerateFaultResponse(header, WsFaultType.WsaEndpointUnavailable, "Service Unavailable (busy)", context.Version));

                            System.Ext.Console.Write("Http max thread count exceeded. Request ignored.");
                        }
                        else
                        {
                            // Try to get a processing thread and process the request
                            m_threadManager.StartNewThread(processor);
                        }
                    }
                }
                catch
                {
                    if (!m_isStarted)
                    {
                        break;
                    }
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Creates an empty instance of the UdpProcess class.
 /// </summary>
 public WsUdpMessageProcessor(WsServiceEndpoints serviceEndpoints, RequestContext request) 
 {
     m_serviceEndpoints = serviceEndpoints;
     m_request = request;
 }
        //private const int ReadPayload = 0x800;

        /// <summary>
        /// HttpProcess()
        ///     Summary:
        ///         Main Http processor class.
        /// </summary>
        /// <param name="serviceEndpoints">A collection of service endpoints.</param>
        /// <param name="s">
        /// Socket s
        /// </param>
        public WsHttpMessageProcessor(WsServiceEndpoints serviceEndpoints, _Bind.RequestContext context)
        {
            m_context = context;
            m_serviceEndpoints = serviceEndpoints;
        }
Esempio n. 5
0
        //private const int ReadPayload = 0x800;

        /// <summary>
        /// HttpProcess()
        ///     Summary:
        ///         Main Http processor class.
        /// </summary>
        /// <param name="serviceEndpoints">A collection of service endpoints.</param>
        /// <param name="s">
        /// Socket s
        /// </param>
        public WsHttpMessageProcessor(WsServiceEndpoints serviceEndpoints, _Bind.RequestContext context)
        {
            m_context          = context;
            m_serviceEndpoints = serviceEndpoints;
        }
Esempio n. 6
0
        /// <summary>
        /// Parses a transport message and builds a header object and envelope document then calls processRequest
        /// on a service endpoint.
        /// </summary>
        /// <param name="soapRequest">WsRequestMessage object containing a raw soap message or mtom soap request.</param>
        /// <returns>WsResponseMessage object containing the soap response returned from a service endpoint.</returns>
        private WsMessage ProcessRequestMessage(_Bind.RequestContext context)
        {
            // Now check for implementation specific service endpoints.
            IWsServiceEndpoint serviceEndpoint = null;
            string             endpointAddress;
            WsMessage          soapRequest = context.Message;
            WsWsaHeader        header      = soapRequest.Header;

            // If this is Uri convert it
            if (header.To.IndexOf("urn") == 0 || header.To.IndexOf("http") == 0)
            {
                // Convert to address to Uri
                Uri toUri;
                try
                {
                    toUri = new Uri(header.To);
                }
                catch
                {
                    System.Ext.Console.Write("Unsupported Header.To Uri format: " + header.To);
                    return(WsFault.GenerateFaultResponse(header, WsFaultType.ArgumentException, "Unsupported Header.To Uri format", context.Version));
                }

                // Convert the to address to a Urn:uuid if it is an Http endpoint
                if (toUri.Scheme == "urn")
                {
                    endpointAddress = toUri.AbsoluteUri;
                }
                else if (toUri.Scheme == "http")
                {
                    endpointAddress = "urn:uuid:" + toUri.AbsolutePath.Substring(1);
                }
                else
                {
                    endpointAddress = header.To;
                }
            }
            else
            {
                endpointAddress = "urn:uuid:" + header.To;
            }

            // Look for a service at the requested endpoint that contains an operation matching the Action
            IWsServiceEndpoint ep = m_serviceEndpoints[endpointAddress];

            if (ep != null)
            {
                if (ep.ServiceOperations[header.Action] != null)
                {
                    serviceEndpoint = ep;
                }
            }

            if (serviceEndpoint == null)
            {
                IWsServiceEndpoint mex = m_serviceEndpoints.DiscoMexService; // mex endpoint

                // If either the MEX endpoint or any of the services endpoints match
                // the requested endpoint then see if the requested action is for the discovery
                // service.
                if (mex != null &&
                    (mex.EndpointAddress == endpointAddress || ep != null) &&
                    mex.ServiceOperations[header.Action] != null)
                {
                    serviceEndpoint = mex;
                }
            }

            // If a matching service endpoint is found call operation
            if (serviceEndpoint != null)
            {
                // Process the request
                WsMessage response;
                try
                {
                    response = serviceEndpoint.ProcessRequest(soapRequest);
                }
                catch (WsFaultException e)
                {
                    return(WsFault.GenerateFaultResponse(e, context.Version));
                }
                catch (Exception e)
                {
                    return(WsFault.GenerateFaultResponse(header, WsFaultType.Exception, e.ToString(), context.Version));
                }

                return(response);
            }

            // Unreachable endpoint requested. Generate fault response
            return(WsFault.GenerateFaultResponse(header, WsFaultType.WsaDestinationUnreachable, "Unknown service endpoint", context.Version));
        }
Esempio n. 7
0
        /// <summary>
        /// Parses a Udp transport message and builds a header object and envelope document then calls processRequest
        /// on a service endpoint contained.
        /// </summary>
        /// <param name="soapRequest">A byte array containing a raw soap request message.  If null no check is performed.</param>
        /// <param name="messageCheck">A WsMessageCheck objct used to test for duplicate request.</param>
        /// <param name="remoteEP">The remote endpoint address of the requestor.</param>
        /// <returns>A byte array containing a soap response message returned from a service endpoint.</returns>
        public WsMessage ProcessRequestMessage(RequestContext request)
        {
            // Parse and validate the soap message
            WsMessage   message = request.Message;
            WsWsaHeader header  = message.Header;

            // Check Udp service endpoints collection for a target service.
            int count = m_serviceEndpoints.Count;

            // DO NOT USE the subscript operator for endpoint addresses (WsServiceEndpoints[EnpointAddress])
            // for local host testing there are multiple endpoints with the same address but different operations
            for (int i = 0; i < count; i++)
            {
                IWsServiceEndpoint serviceEndpoint = m_serviceEndpoints[i];

                if (serviceEndpoint.EndpointAddress == header.To)
                {
                    if (serviceEndpoint.ServiceOperations[header.Action] != null)
                    {
                        // Don't block discovery processes.
                        serviceEndpoint.BlockingCall = false;
                        try
                        {
                            return serviceEndpoint.ProcessRequest(message);
                        }
                        catch (WsFaultException e)
                        {
                            return WsFault.GenerateFaultResponse(e, request.Version);
                        }
                        catch
                        {
                            // If a valid Action is not found, fault
                            return WsFault.GenerateFaultResponse(header, WsFaultType.WsaDestinationUnreachable, "To: " + header.To + " Action: " + header.Action, request.Version);
                        }
                    }
                }
            }

            // Return null if service endpoint was not found
            System.Ext.Console.Write("Udp service endpoint was not found.");
            System.Ext.Console.Write("  Endpoint Address: " + header.To);
            System.Ext.Console.Write("  Action: " + header.Action);

            return null;
        }