protected Message ExecuteMessage(Message message, EndpointAttributes endpointAttributes, IHttpRequest httpRequest, IHttpResponse httpResponse) { var soapFeature = endpointAttributes.ToSoapFeature(); EndpointHost.Config.AssertFeatures(soapFeature); var httpReq = HttpContext.Current != null && httpRequest == null ? new HttpRequestWrapper(HttpContext.Current.Request) : httpRequest; var httpRes = HttpContext.Current != null && httpResponse == null ? new HttpResponseWrapper(HttpContext.Current.Response) : httpResponse; if (httpReq == null) { throw new ArgumentNullException("httpRequest"); } if (httpRes == null) { throw new ArgumentNullException("httpResponse"); } if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes)) { return(PrepareEmptyResponse(message, httpReq)); } var requestMsg = message ?? GetRequestMessageFromStream(httpReq.InputStream); string requestXml = GetRequestXml(requestMsg); var requestType = GetRequestType(requestMsg, requestXml); if (!EndpointHost.Metadata.CanAccess(endpointAttributes, soapFeature.ToFormat(), requestType.Name)) { throw EndpointHost.Config.UnauthorizedAccess(endpointAttributes); } try { var useXmlSerializerRequest = requestType.HasAttribute <XmlSerializerFormatAttribute>(); var request = useXmlSerializerRequest ? XmlSerializableDeserializer.Instance.Parse(requestXml, requestType) : DataContractDeserializer.Instance.Parse(requestXml, requestType); var requiresSoapMessage = request as IRequiresSoapMessage; if (requiresSoapMessage != null) { requiresSoapMessage.Message = requestMsg; } httpReq.OperationName = requestType.Name; httpReq.SetItem("SoapMessage", requestMsg); var hasRequestFilters = EndpointHost.RequestFilters.Count > 0 || FilterAttributeCache.GetRequestFilterAttributes(request.GetType()).Any(); if (hasRequestFilters && EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) { return(EmptyResponse(requestMsg, requestType)); } var response = ExecuteService(request, endpointAttributes, httpReq, httpRes); var hasResponseFilters = EndpointHost.ResponseFilters.Count > 0 || FilterAttributeCache.GetResponseFilterAttributes(response.GetType()).Any(); if (hasResponseFilters && EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) { return(EmptyResponse(requestMsg, requestType)); } var httpResult = response as IHttpResult; if (httpResult != null) { response = httpResult.Response; } var useXmlSerializerResponse = response.GetType().HasAttribute <XmlSerializerFormatAttribute>(); if (useXmlSerializerResponse) { return(requestMsg.Headers.Action == null ? Message.CreateMessage(requestMsg.Version, null, response, new XmlSerializerWrapper(response.GetType())) : Message.CreateMessage(requestMsg.Version, requestType.Name + "Response", response, new XmlSerializerWrapper(response.GetType()))); } return(requestMsg.Headers.Action == null ? Message.CreateMessage(requestMsg.Version, null, response) : Message.CreateMessage(requestMsg.Version, requestType.Name + "Response", response)); } catch (Exception ex) { throw new SerializationException("3) Error trying to deserialize requestType: " + requestType + ", xml body: " + requestXml, ex); } }
protected Message ExecuteMessage(Message requestMsg, EndpointAttributes endpointAttributes, IHttpRequest httpRequest, IHttpResponse httpResponse) { if ((EndpointAttributes.Soap11 & this.HandlerAttributes) == EndpointAttributes.Soap11) { EndpointHost.Config.AssertFeatures(Feature.Soap11); } else if ((EndpointAttributes.Soap12 & this.HandlerAttributes) == EndpointAttributes.Soap12) { EndpointHost.Config.AssertFeatures(Feature.Soap12); } string requestXml; using (var reader = requestMsg.GetReaderAtBodyContents()) { requestXml = reader.ReadOuterXml(); } var requestType = GetRequestType(requestMsg, requestXml); try { var request = DataContractDeserializer.Instance.Parse(requestXml, requestType); var requiresSoapMessage = request as IRequiresSoapMessage; if (requiresSoapMessage != null) { requiresSoapMessage.Message = requestMsg; } var httpReq = HttpContext.Current != null ? new HttpRequestWrapper(requestType.Name, HttpContext.Current.Request) : httpRequest; var httpRes = HttpContext.Current != null ? new HttpResponseWrapper(HttpContext.Current.Response) : httpResponse; if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes)) { return(EmptyResponse(requestMsg, requestType)); } var hasRequestFilters = EndpointHost.RequestFilters.Count > 0 || FilterAttributeCache.GetRequestFilterAttributes(request.GetType()).Any(); if (hasRequestFilters && EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) { return(EmptyResponse(requestMsg, requestType)); } var response = ExecuteService(request, endpointAttributes, httpReq, httpRes); var hasResponseFilters = EndpointHost.ResponseFilters.Count > 0 || FilterAttributeCache.GetResponseFilterAttributes(response.GetType()).Any(); if (hasResponseFilters && EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) { return(EmptyResponse(requestMsg, requestType)); } var httpResult = response as IHttpResult; if (httpResult != null) { response = httpResult.Response; } return(requestMsg.Headers.Action == null ? Message.CreateMessage(requestMsg.Version, null, response) : Message.CreateMessage(requestMsg.Version, requestType.Name + "Response", response)); } catch (Exception ex) { throw new SerializationException("3) Error trying to deserialize requestType: " + requestType + ", xml body: " + requestXml, ex); } }