void SerializeFault(HttpContext context, SoapServerMessage requestMessage, Exception ex) { SoapException soex = ex as SoapException; if (soex == null) { soex = new SoapException(ex.ToString(), WebServiceHelper.ServerFaultCode(requestMessage != null && requestMessage.IsSoap12), ex); } SoapServerMessage faultMessage; if (requestMessage != null) { faultMessage = new SoapServerMessage(context.Request, soex, requestMessage.MethodStubInfo, requestMessage.Server, requestMessage.Stream); } else { faultMessage = new SoapServerMessage(context.Request, soex, null, null, null); } object soapVer = context.Items ["WebServiceSoapVersion"]; if (soapVer != null) { faultMessage.SetSoapVersion((SoapProtocolVersion)soapVer); } SerializeResponse(context.Response, faultMessage); context.Response.End(); return; }
string ReadActionFromRequestElement(Stream stream, Encoding encoding, bool soap12) { string envNS = soap12 ? WebServiceHelper.Soap12EnvelopeNamespace : WebServiceHelper.SoapEnvelopeNamespace; try { StreamReader reader = new StreamReader(stream, encoding, false); XmlTextReader xmlReader = new XmlTextReader(reader); xmlReader.MoveToContent(); xmlReader.ReadStartElement("Envelope", envNS); while (!(xmlReader.NodeType == XmlNodeType.Element && xmlReader.LocalName == "Body" && xmlReader.NamespaceURI == envNS)) { xmlReader.Skip(); } xmlReader.ReadStartElement("Body", envNS); xmlReader.MoveToContent(); return(xmlReader.LocalName); } catch (Exception ex) { string errmsg = "The root element for the request could not be determined. "; errmsg += "When RoutingStyle is set to RequestElement, SoapExtensions configured "; errmsg += "via an attribute on the method cannot modify the request stream before it is read. "; errmsg += "The extension must be configured via the SoapExtensionTypes element in web.config "; errmsg += "or the request must arrive at the server as clear text."; throw new SoapException(errmsg, WebServiceHelper.ServerFaultCode(soap12), ex); } }