/// <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 byte[] ProcessRequestMessage() { Debug.Assert(m_messageCheck != null && m_remoteEP != null); // Parse and validate the soap message WsWsaHeader header; XmlReader reader; try { reader = WsSoapMessageParser.ParseSoapMessage(m_soapMessage, out header); } catch { return(null); } try { if (m_messageCheck.IsDuplicate(header.MessageID, m_remoteEP.ToString()) == true) { System.Ext.Console.Write("Duplicate \"" + header.Action + "\" request received"); System.Ext.Console.Write("Request Ignored."); return(null); } // Check Udp service endpoints collection for a target service. IWsServiceEndpoint serviceEndpoint = m_serviceEndpoints[header.To]; if (serviceEndpoint != null && serviceEndpoint.ServiceOperations[header.Action] != null) { // Don't block discovery processes. serviceEndpoint.BlockingCall = false; try { return(serviceEndpoint.ProcessRequest(header, reader)); } catch { return(null); } } // 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); } finally { reader.Close(); } }
/// <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); }
/// <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(WsMessage soapRequest) { // Parse and validate the soap message WsWsaHeader header; XmlReader reader; try { reader = WsSoapMessageParser.ParseSoapMessage(soapRequest.Message, out header); } catch (WsFaultException e) { return(WsFault.GenerateFaultResponse(e)); } try { // Now check for implementation specific service endpoints. IWsServiceEndpoint serviceEndpoint = null; string endpointAddress = null; // 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")); } // 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.AbsoluteUri.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 // This hack is required because service spec writers determined that more than one service type // can live at a single endpoint address. Why you would want to break the object model and allow // this feature is unknown so for now we must hack. bool eventingReqFlag = true; for (int i = 0; i < m_serviceEndpoints.Count; ++i) { if (m_serviceEndpoints[i].EndpointAddress == endpointAddress) { if (m_serviceEndpoints[i].ServiceOperations[header.Action] != null) { serviceEndpoint = m_serviceEndpoints[i]; eventingReqFlag = false; break; } } } // Worst part of the hack: If no matching endpoint is found assume this is an event subscription // request and call the base eventing methods on any class. They had to be Global because of this feature. // Now the subscription manager must determine globally that a suitable web service is found. Yuch!! if (eventingReqFlag) { serviceEndpoint = m_serviceEndpoints[0]; } // If a matching service endpoint is found call operation if (serviceEndpoint != null) { // If this is mtom, copy the requests body parts to the hosted services body parts // prior to making the call if (soapRequest.MessageType == WsMessageType.Mtom) { serviceEndpoint.BodyParts = soapRequest.BodyParts; } // Process the request byte[] response; try { response = serviceEndpoint.ProcessRequest(header, reader); } catch (WsFaultException e) { return(WsFault.GenerateFaultResponse(e)); } catch (Exception e) { return(WsFault.GenerateFaultResponse(header, WsFaultType.Exception, e.ToString())); } // If the message response type is Soap return a SoapMessage type if (serviceEndpoint.MessageType == WsMessageType.Soap) { if (response == null) { return(null); } return(new WsMessage(response)); } // If the response is Mtom build an mtom response message else // if (serviceEndpoint.MessageType == WsMessageType.Mtom) { return(new WsMessage(serviceEndpoint.BodyParts)); } } // Unreachable endpoint requested. Generate fault response return(WsFault.GenerateFaultResponse(header, WsFaultType.WsaDestinationUnreachable, "Unknown service endpoint")); } finally { reader.Close(); } }
/// <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(WsMessage soapRequest) { // Now check for implementation specific service endpoints. IWsServiceEndpoint serviceEndpoint = null; string endpointAddress; 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", m_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.AbsoluteUri.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; } else { ep = m_serviceEndpoints[0]; // mex endpoint if (ep.ServiceOperations[header.Action] != null) { serviceEndpoint = ep; } } } // 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, m_context.Version)); } catch (Exception e) { return(WsFault.GenerateFaultResponse(header, WsFaultType.Exception, e.ToString(), m_context.Version)); } return(response); } // Unreachable endpoint requested. Generate fault response return(WsFault.GenerateFaultResponse(header, WsFaultType.WsaDestinationUnreachable, "Unknown service endpoint", m_context.Version)); }