/// <summary> /// Creates a http service host. /// </summary> /// <param name="port">An integer containing the port number this host will listen on.</param> /// <param name="serviceEndpoints">A collection of service endpoints this transport service can dispatch to.</param> public WsHttpServiceHost(_Bind.Binding binding, WsServiceEndpoints serviceEndpoints) { m_threadManager = new WsThreadManager(5, "Http"); m_binding = binding; m_serviceEndpoints = serviceEndpoints; m_isStarted = false; }
public void Start(_Bind.ServerBindingContext ctx) { if (m_isStarted) throw new InvalidOperationException(); m_isStarted = true; m_replyChannel = m_binding.CreateServerChannel(ctx); m_replyChannel.Open(); m_thread = new Thread(new ThreadStart(this.Listen)); m_thread.Start(); }
/// <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); }
//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; }