void Serialize(SoapClientMessage message) { Stream stream = message.Stream; SoapClientMethod method = message.Method; bool isEncoded = method.use == SoapBindingUse.Encoded; // Serialize the message. string envelopeNs = EnvelopeNs; string encodingNs = EncodingNs; XmlWriter writer = GetWriterForMessage(message, 1024); if (writer == null) { throw new InvalidOperationException(Res.GetString(Res.WebNullWriterForMessage)); } writer.WriteStartDocument(); writer.WriteStartElement(Soap.Prefix, Soap.Element.Envelope, envelopeNs); writer.WriteAttributeString("xmlns", Soap.Prefix, null, envelopeNs); if (isEncoded) { writer.WriteAttributeString("xmlns", "soapenc", null, encodingNs); writer.WriteAttributeString("xmlns", "tns", null, clientType.serviceNamespace); writer.WriteAttributeString("xmlns", "types", null, SoapReflector.GetEncodedNamespace(clientType.serviceNamespace, clientType.serviceDefaultIsEncoded)); } writer.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace); writer.WriteAttributeString("xmlns", "xsd", null, XmlSchema.Namespace); SoapHeaderHandling.WriteHeaders(writer, method.inHeaderSerializer, message.Headers, method.inHeaderMappings, SoapHeaderDirection.In, isEncoded, clientType.serviceNamespace, clientType.serviceDefaultIsEncoded, envelopeNs); writer.WriteStartElement(Soap.Element.Body, envelopeNs); if (isEncoded && version != SoapProtocolVersion.Soap12) // don't write encodingStyle on soap:Body for soap 1.2 { writer.WriteAttributeString("soap", Soap.Attribute.EncodingStyle, null, encodingNs); } object[] parameters = message.GetParameterValues(); TraceMethod caller = Tracing.On ? new TraceMethod(this, "Serialize") : null; if (Tracing.On) { Tracing.Enter(Tracing.TraceId(Res.TraceWriteRequest), caller, new TraceMethod(method.parameterSerializer, "Serialize", writer, parameters, null, isEncoded ? encodingNs : null)); } method.parameterSerializer.Serialize(writer, parameters, null, isEncoded ? encodingNs : null); if (Tracing.On) { Tracing.Exit(Tracing.TraceId(Res.TraceWriteRequest), caller); } writer.WriteEndElement(); writer.WriteEndElement(); writer.Flush(); // run the after serialize extension pass. message.SetStage(SoapMessageStage.AfterSerialize); message.RunExtensions(message.initializedExtensions, true); }
private void Serialize(SoapClientMessage message) { Stream stream = message.Stream; SoapClientMethod method = message.Method; bool isEncoded = method.use == SoapBindingUse.Encoded; string envelopeNs = this.EnvelopeNs; string encodingNs = this.EncodingNs; XmlWriter writerForMessage = this.GetWriterForMessage(message, 1024); if (writerForMessage == null) { throw new InvalidOperationException(System.Web.Services.Res.GetString("WebNullWriterForMessage")); } writerForMessage.WriteStartDocument(); writerForMessage.WriteStartElement("soap", "Envelope", envelopeNs); writerForMessage.WriteAttributeString("xmlns", "soap", (string)null, envelopeNs); if (isEncoded) { writerForMessage.WriteAttributeString("xmlns", "soapenc", (string)null, encodingNs); writerForMessage.WriteAttributeString("xmlns", "tns", (string)null, this.clientType.serviceNamespace); writerForMessage.WriteAttributeString("xmlns", "types", (string)null, SoapReflector.GetEncodedNamespace(this.clientType.serviceNamespace, this.clientType.serviceDefaultIsEncoded)); } writerForMessage.WriteAttributeString("xmlns", "xsi", (string)null, "http://www.w3.org/2001/XMLSchema-instance"); writerForMessage.WriteAttributeString("xmlns", "xsd", (string)null, "http://www.w3.org/2001/XMLSchema"); SoapHeaderHandling.WriteHeaders(writerForMessage, method.inHeaderSerializer, message.Headers, method.inHeaderMappings, SoapHeaderDirection.In, isEncoded, this.clientType.serviceNamespace, this.clientType.serviceDefaultIsEncoded, envelopeNs); writerForMessage.WriteStartElement("Body", envelopeNs); if (isEncoded && this.version != SoapProtocolVersion.Soap12) { writerForMessage.WriteAttributeString("soap", "encodingStyle", (string)null, encodingNs); } object[] parameterValues = message.GetParameterValues(); TraceMethod caller = Tracing.On ? new TraceMethod((object)this, "Serialize", new object[0]) : (TraceMethod)null; if (Tracing.On) { Tracing.Enter(Tracing.TraceId("TraceWriteRequest"), caller, new TraceMethod((object)method.parameterSerializer, "Serialize", new object[4] { (object)writerForMessage, (object)parameterValues, null, isEncoded ? (object)encodingNs : (object)(string)null })); } method.parameterSerializer.Serialize(writerForMessage, (object)parameterValues, (XmlSerializerNamespaces)null, isEncoded ? encodingNs : (string)null); if (Tracing.On) { Tracing.Exit(Tracing.TraceId("TraceWriteRequest"), caller); } writerForMessage.WriteEndElement(); writerForMessage.WriteEndElement(); writerForMessage.Flush(); message.SetStage(SoapMessageStage.AfterSerialize); message.RunExtensions(message.initializedExtensions, true); }
void Serialize(SoapClientMessage message) { Stream stream = message.Stream; SoapClientMethod method = message.Method; bool isEncoded = method.use == SoapBindingUse.Encoded; // Serialize the message. string envelopeNs = EnvelopeNs; string encodingNs = EncodingNs; StreamWriter sw = new StreamWriter(stream, RequestEncoding != null ? RequestEncoding : new UTF8Encoding(false), 128); XmlTextWriter writer = isEncoded && message.Headers.Count > 0 ? new XmlSpecialTextWriter(sw, version) : new XmlTextWriter(sw); writer.WriteStartDocument(); writer.WriteStartElement("soap", Soap.Envelope, envelopeNs); writer.WriteAttributeString("xmlns", "soap", null, envelopeNs); if (isEncoded) { writer.WriteAttributeString("xmlns", "soapenc", null, encodingNs); writer.WriteAttributeString("xmlns", "tns", null, clientType.serviceNamespace); writer.WriteAttributeString("xmlns", "types", null, SoapReflector.GetEncodedNamespace(clientType.serviceNamespace, clientType.serviceDefaultIsEncoded)); } writer.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace); writer.WriteAttributeString("xmlns", "xsd", null, XmlSchema.Namespace); SoapHeaderHandling.WriteHeaders(writer, method.inHeaderSerializer, message.Headers, method.inHeaderMappings, SoapHeaderDirection.In, isEncoded, clientType.serviceNamespace, clientType.serviceDefaultIsEncoded, envelopeNs); writer.WriteStartElement(Soap.Body, envelopeNs); if (isEncoded) { writer.WriteAttributeString("soap", Soap.EncodingStyle, null, encodingNs); } // SOAP12: not using encodingStyle //method.parameterSerializer.Serialize(writer, message.GetParameterValues(), null, isEncoded ? encodingNs : null); method.parameterSerializer.Serialize(writer, message.GetParameterValues(), null); writer.WriteEndElement(); writer.WriteEndElement(); writer.Flush(); // run the after serialize extension pass. message.SetStage(SoapMessageStage.AfterSerialize); message.RunExtensions(message.initializedExtensions); }
object[] ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, bool asyncCall) { SoapClientMethod method = message.Method; // HttpWebResponse httpResponse = response as HttpWebResponse; int statusCode = httpResponse != null ? (int)httpResponse.StatusCode : -1; if (statusCode >= 300 && statusCode != 500 && statusCode != 400) throw new WebException(RequestResponseUtils.CreateResponseExceptionString(httpResponse, responseStream), null, WebExceptionStatus.ProtocolError, httpResponse); message.Headers.Clear(); message.SetStream(responseStream); message.InitExtensionStreamChain(message.initializedExtensions); message.SetStage(SoapMessageStage.BeforeDeserialize); message.ContentType = response.ContentType; message.ContentEncoding = response.Headers[ContentType.ContentEncoding]; message.RunExtensions(message.initializedExtensions, false); if (method.oneWay && (httpResponse == null || (int)httpResponse.StatusCode != 500)) { return new object[0]; } // this statusCode check is just so we don't repeat the contentType check we did above bool isSoap = ContentType.IsSoap(message.ContentType); if (!isSoap || (isSoap && (httpResponse != null) && (httpResponse.ContentLength == 0))) { // special-case 400 since we exempted it above on the off-chance it might be a soap 1.2 sender fault. // based on the content-type, it looks like it's probably just a regular old 400 if (statusCode == 400) throw new WebException(RequestResponseUtils.CreateResponseExceptionString(httpResponse, responseStream), null, WebExceptionStatus.ProtocolError, httpResponse); else throw new InvalidOperationException(Res.GetString(Res.WebResponseContent, message.ContentType, HttpContentType) + Environment.NewLine + RequestResponseUtils.CreateResponseExceptionString(response, responseStream)); } if (message.Exception != null) { throw message.Exception; } // perf fix: changed buffer size passed to StreamReader int bufferSize; if (asyncCall || httpResponse == null) bufferSize = 512; else { bufferSize = RequestResponseUtils.GetBufferSize((int)httpResponse.ContentLength); } XmlReader reader = GetReaderForMessage(message, bufferSize); if (reader == null) throw new InvalidOperationException(Res.GetString(Res.WebNullReaderForMessage)); reader.MoveToContent(); int depth = reader.Depth; // should be able to handle no ns, soap 1.1 ns, or soap 1.2 ns string encodingNs = EncodingNs; string envelopeNs = reader.NamespaceURI; if (envelopeNs == null || envelopeNs.Length == 0) // ok to omit namespace -- assume correct version reader.ReadStartElement(Soap.Element.Envelope); else if (reader.NamespaceURI == Soap.Namespace) reader.ReadStartElement(Soap.Element.Envelope, Soap.Namespace); else if (reader.NamespaceURI == Soap12.Namespace) reader.ReadStartElement(Soap.Element.Envelope, Soap12.Namespace); else throw new SoapException(Res.GetString(Res.WebInvalidEnvelopeNamespace, envelopeNs, EnvelopeNs), SoapException.VersionMismatchFaultCode); reader.MoveToContent(); SoapHeaderHandling headerHandler = new SoapHeaderHandling(); headerHandler.ReadHeaders(reader, method.outHeaderSerializer, message.Headers, method.outHeaderMappings, SoapHeaderDirection.Out | SoapHeaderDirection.Fault, envelopeNs, method.use == SoapBindingUse.Encoded ? encodingNs : null, false); reader.MoveToContent(); reader.ReadStartElement(Soap.Element.Body, envelopeNs); reader.MoveToContent(); if (reader.IsStartElement(Soap.Element.Fault, envelopeNs)) { message.Exception = ReadSoapException(reader); } else { if (method.oneWay) { reader.Skip(); message.SetParameterValues(new object[0]); } else { TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadResponse") : null; bool isEncodedSoap = method.use == SoapBindingUse.Encoded; if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceReadResponse), caller, new TraceMethod(method.returnSerializer, "Deserialize", reader, isEncodedSoap ? encodingNs : null)); bool useDeserializationEvents = !isEncodedSoap && (WebServicesSection.Current.SoapEnvelopeProcessing.IsStrict || Tracing.On); if (useDeserializationEvents) { XmlDeserializationEvents events = Tracing.On ? Tracing.GetDeserializationEvents() : RuntimeUtils.GetDeserializationEvents(); message.SetParameterValues((object[])method.returnSerializer.Deserialize(reader, null, events)); } else { message.SetParameterValues((object[])method.returnSerializer.Deserialize(reader, isEncodedSoap ? encodingNs : null)); } if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceReadResponse), caller); } } // Consume soap:Body and soap:Envelope closing tags while (depth < reader.Depth && reader.Read()) { // Nothing, just read on } // consume end tag if (reader.NodeType == XmlNodeType.EndElement) { reader.Read(); } message.SetStage(SoapMessageStage.AfterDeserialize); message.RunExtensions(message.initializedExtensions, false); SoapHeaderHandling.SetHeaderMembers(message.Headers, this, method.outHeaderMappings, SoapHeaderDirection.Out | SoapHeaderDirection.Fault, true); if (message.Exception != null) throw message.Exception; return message.GetParameterValues(); }
void Serialize(SoapClientMessage message) { Stream stream = message.Stream; SoapClientMethod method = message.Method; bool isEncoded = method.use == SoapBindingUse.Encoded; // Serialize the message. string envelopeNs = EnvelopeNs; string encodingNs = EncodingNs; XmlWriter writer = GetWriterForMessage(message, 1024); if (writer == null) throw new InvalidOperationException(Res.GetString(Res.WebNullWriterForMessage)); writer.WriteStartDocument(); writer.WriteStartElement(Soap.Prefix, Soap.Element.Envelope, envelopeNs); writer.WriteAttributeString("xmlns", Soap.Prefix, null, envelopeNs); if (isEncoded) { writer.WriteAttributeString("xmlns", "soapenc", null, encodingNs); writer.WriteAttributeString("xmlns", "tns", null, clientType.serviceNamespace); writer.WriteAttributeString("xmlns", "types", null, SoapReflector.GetEncodedNamespace(clientType.serviceNamespace, clientType.serviceDefaultIsEncoded)); } writer.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace); writer.WriteAttributeString("xmlns", "xsd", null, XmlSchema.Namespace); SoapHeaderHandling.WriteHeaders(writer, method.inHeaderSerializer, message.Headers, method.inHeaderMappings, SoapHeaderDirection.In, isEncoded, clientType.serviceNamespace, clientType.serviceDefaultIsEncoded, envelopeNs); writer.WriteStartElement(Soap.Element.Body, envelopeNs); if (isEncoded && version != SoapProtocolVersion.Soap12) // don't write encodingStyle on soap:Body for soap 1.2 writer.WriteAttributeString("soap", Soap.Attribute.EncodingStyle, null, encodingNs); object[] parameters = message.GetParameterValues(); TraceMethod caller = Tracing.On ? new TraceMethod(this, "Serialize") : null; if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceWriteRequest), caller, new TraceMethod(method.parameterSerializer, "Serialize", writer, parameters, null, isEncoded ? encodingNs : null)); method.parameterSerializer.Serialize(writer, parameters, null, isEncoded ? encodingNs : null); if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceWriteRequest), caller); writer.WriteEndElement(); writer.WriteEndElement(); writer.Flush(); // run the after serialize extension pass. message.SetStage(SoapMessageStage.AfterSerialize); message.RunExtensions(message.initializedExtensions, true); }
object[] ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, bool asyncCall) { SoapClientMethod method = message.Method; // CONSIDER,yannc: use the SoapExtensionStream here as well so we throw exceptions // : if the extension touches stream properties/methods in before deserialize. // note that if there is an error status code then the response might be content-type=text/plain. HttpWebResponse httpResponse = response as HttpWebResponse; int statusCode = httpResponse != null ? (int)httpResponse.StatusCode : -1; if (statusCode >= 300 && statusCode != 500 && statusCode != 400) { throw new WebException(RequestResponseUtils.CreateResponseExceptionString(httpResponse, responseStream), null, WebExceptionStatus.ProtocolError, httpResponse); } message.Headers.Clear(); message.SetStream(responseStream); message.InitExtensionStreamChain(message.initializedExtensions); message.SetStage(SoapMessageStage.BeforeDeserialize); message.ContentType = response.ContentType; message.ContentEncoding = response.Headers[ContentType.ContentEncoding]; message.RunExtensions(message.initializedExtensions); if (method.oneWay && (httpResponse == null || (int)httpResponse.StatusCode != 500)) { return(new object[0]); } // this statusCode check is just so we don't repeat the contentType check we did above if (!ContentType.IsSoap(message.ContentType)) { // special-case 400 since we exempted it above on the off-chance it might be a soap 1.2 sender fault. // based on the content-type, it looks like it's probably just a regular old 400 if (statusCode == 400) { throw new WebException(RequestResponseUtils.CreateResponseExceptionString(httpResponse, responseStream), null, WebExceptionStatus.ProtocolError, httpResponse); } else { throw new InvalidOperationException(Res.GetString(Res.WebResponseContent, message.ContentType, HttpContentType) + "\r\n" + RequestResponseUtils.CreateResponseExceptionString(response, responseStream)); } } Encoding enc = RequestResponseUtils.GetEncoding(message.ContentType); // perf fix: changed buffer size passed to StreamReader int bufferSize; if (asyncCall || httpResponse == null) { bufferSize = 512; } else { int contentLength = (int)httpResponse.ContentLength; if (contentLength == -1) { bufferSize = 8000; } else if (contentLength <= 16000) { bufferSize = contentLength; } else { bufferSize = 16000; } } XmlTextReader reader; if (enc != null) { reader = new XmlTextReader(new StreamReader(message.Stream, enc, true, bufferSize)); } else { // CONSIDER: do i need to pass a buffer size somehow? reader = new XmlTextReader(message.Stream); } reader.Normalization = true; reader.XmlResolver = null; reader.MoveToContent(); // should be able to handle no ns, soap 1.1 ns, or soap 1.2 ns string encodingNs = EncodingNs; string envelopeNs = reader.NamespaceURI; if (envelopeNs == null || envelopeNs.Length == 0) { // ok to omit namespace -- assume correct version reader.ReadStartElement(Soap.Envelope); } else if (reader.NamespaceURI == Soap.Namespace) { reader.ReadStartElement(Soap.Envelope, Soap.Namespace); } else if (reader.NamespaceURI == Soap12.Namespace) { reader.ReadStartElement(Soap.Envelope, Soap12.Namespace); } else { throw new SoapException(Res.GetString(Res.WebInvalidEnvelopeNamespace, envelopeNs, EnvelopeNs), SoapException.VersionMismatchFaultCode); } reader.MoveToContent(); SoapHeaderHandling headerHandler = new SoapHeaderHandling(); headerHandler.ReadHeaders(reader, method.outHeaderSerializer, message.Headers, method.outHeaderMappings, SoapHeaderDirection.Out | SoapHeaderDirection.Fault, envelopeNs, method.use == SoapBindingUse.Encoded ? encodingNs : null); reader.MoveToContent(); reader.ReadStartElement(Soap.Body, envelopeNs); reader.MoveToContent(); if (reader.IsStartElement(Soap.Fault, envelopeNs)) { message.SetException(ReadSoapException(reader)); } else { if (method.oneWay) { reader.Skip(); message.SetParameterValues(new object[0]); } else { // SOAP12: not using encodingStyle //message.SetParameterValues((object[])method.returnSerializer.Deserialize(reader, method.use == SoapBindingUse.Encoded ? encodingNs : null)); message.SetParameterValues((object[])method.returnSerializer.Deserialize(reader)); } } while (reader.NodeType == XmlNodeType.Whitespace) { reader.Skip(); } if (reader.NodeType == XmlNodeType.None) { reader.Skip(); } else { reader.ReadEndElement(); } while (reader.NodeType == XmlNodeType.Whitespace) { reader.Skip(); } if (reader.NodeType == XmlNodeType.None) { reader.Skip(); } else { reader.ReadEndElement(); } message.SetStage(SoapMessageStage.AfterDeserialize); message.RunExtensions(message.initializedExtensions); SoapHeaderHandling.SetHeaderMembers(message.Headers, this, method.outHeaderMappings, SoapHeaderDirection.Out | SoapHeaderDirection.Fault, true); if (message.Exception != null) { throw message.Exception; } return(message.GetParameterValues()); }
object[] ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, bool asyncCall) { SoapClientMethod method = message.Method; // HttpWebResponse httpResponse = response as HttpWebResponse; int statusCode = httpResponse != null ? (int)httpResponse.StatusCode : -1; if (statusCode >= 300 && statusCode != 500 && statusCode != 400) { throw new WebException(RequestResponseUtils.CreateResponseExceptionString(httpResponse, responseStream), null, WebExceptionStatus.ProtocolError, httpResponse); } message.Headers.Clear(); message.SetStream(responseStream); message.InitExtensionStreamChain(message.initializedExtensions); message.SetStage(SoapMessageStage.BeforeDeserialize); message.ContentType = response.ContentType; message.ContentEncoding = response.Headers[ContentType.ContentEncoding]; message.RunExtensions(message.initializedExtensions, false); if (method.oneWay && (httpResponse == null || (int)httpResponse.StatusCode != 500)) { return(new object[0]); } // this statusCode check is just so we don't repeat the contentType check we did above bool isSoap = ContentType.IsSoap(message.ContentType); if (!isSoap || (isSoap && (httpResponse != null) && (httpResponse.ContentLength == 0))) { // special-case 400 since we exempted it above on the off-chance it might be a soap 1.2 sender fault. // based on the content-type, it looks like it's probably just a regular old 400 if (statusCode == 400) { throw new WebException(RequestResponseUtils.CreateResponseExceptionString(httpResponse, responseStream), null, WebExceptionStatus.ProtocolError, httpResponse); } else { throw new InvalidOperationException(Res.GetString(Res.WebResponseContent, message.ContentType, HttpContentType) + Environment.NewLine + RequestResponseUtils.CreateResponseExceptionString(response, responseStream)); } } if (message.Exception != null) { throw message.Exception; } // perf fix: changed buffer size passed to StreamReader int bufferSize; if (asyncCall || httpResponse == null) { bufferSize = 512; } else { bufferSize = RequestResponseUtils.GetBufferSize((int)httpResponse.ContentLength); } XmlReader reader = GetReaderForMessage(message, bufferSize); if (reader == null) { throw new InvalidOperationException(Res.GetString(Res.WebNullReaderForMessage)); } reader.MoveToContent(); int depth = reader.Depth; // should be able to handle no ns, soap 1.1 ns, or soap 1.2 ns string encodingNs = EncodingNs; string envelopeNs = reader.NamespaceURI; if (envelopeNs == null || envelopeNs.Length == 0) { // ok to omit namespace -- assume correct version reader.ReadStartElement(Soap.Element.Envelope); } else if (reader.NamespaceURI == Soap.Namespace) { reader.ReadStartElement(Soap.Element.Envelope, Soap.Namespace); } else if (reader.NamespaceURI == Soap12.Namespace) { reader.ReadStartElement(Soap.Element.Envelope, Soap12.Namespace); } else { throw new SoapException(Res.GetString(Res.WebInvalidEnvelopeNamespace, envelopeNs, EnvelopeNs), SoapException.VersionMismatchFaultCode); } reader.MoveToContent(); SoapHeaderHandling headerHandler = new SoapHeaderHandling(); headerHandler.ReadHeaders(reader, method.outHeaderSerializer, message.Headers, method.outHeaderMappings, SoapHeaderDirection.Out | SoapHeaderDirection.Fault, envelopeNs, method.use == SoapBindingUse.Encoded ? encodingNs : null, false); reader.MoveToContent(); reader.ReadStartElement(Soap.Element.Body, envelopeNs); reader.MoveToContent(); if (reader.IsStartElement(Soap.Element.Fault, envelopeNs)) { message.Exception = ReadSoapException(reader); } else { if (method.oneWay) { reader.Skip(); message.SetParameterValues(new object[0]); } else { TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadResponse") : null; bool isEncodedSoap = method.use == SoapBindingUse.Encoded; if (Tracing.On) { Tracing.Enter(Tracing.TraceId(Res.TraceReadResponse), caller, new TraceMethod(method.returnSerializer, "Deserialize", reader, isEncodedSoap ? encodingNs : null)); } bool useDeserializationEvents = !isEncodedSoap && (WebServicesSection.Current.SoapEnvelopeProcessing.IsStrict || Tracing.On); if (useDeserializationEvents) { XmlDeserializationEvents events = Tracing.On ? Tracing.GetDeserializationEvents() : RuntimeUtils.GetDeserializationEvents(); message.SetParameterValues((object[])method.returnSerializer.Deserialize(reader, null, events)); } else { message.SetParameterValues((object[])method.returnSerializer.Deserialize(reader, isEncodedSoap ? encodingNs : null)); } if (Tracing.On) { Tracing.Exit(Tracing.TraceId(Res.TraceReadResponse), caller); } } } // Consume soap:Body and soap:Envelope closing tags while (depth < reader.Depth && reader.Read()) { // Nothing, just read on } // consume end tag if (reader.NodeType == XmlNodeType.EndElement) { reader.Read(); } message.SetStage(SoapMessageStage.AfterDeserialize); message.RunExtensions(message.initializedExtensions, false); SoapHeaderHandling.SetHeaderMembers(message.Headers, this, method.outHeaderMappings, SoapHeaderDirection.Out | SoapHeaderDirection.Fault, true); if (message.Exception != null) { throw message.Exception; } return(message.GetParameterValues()); }
private object[] ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, bool asyncCall) { SoapClientMethod method = message.Method; HttpWebResponse httpWebResponse = response as HttpWebResponse; int num1 = httpWebResponse != null ? (int) httpWebResponse.StatusCode : -1; if (num1 >= 300 && num1 != 500 && num1 != 400) throw new WebException(RequestResponseUtils.CreateResponseExceptionString((WebResponse) httpWebResponse, responseStream), (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) httpWebResponse); message.Headers.Clear(); message.SetStream(responseStream); message.InitExtensionStreamChain(message.initializedExtensions); message.SetStage(SoapMessageStage.BeforeDeserialize); message.ContentType = response.ContentType; message.ContentEncoding = ((NameValueCollection) response.Headers)["Content-Encoding"]; message.RunExtensions(message.initializedExtensions, false); if (method.oneWay && (httpWebResponse == null || httpWebResponse.StatusCode != HttpStatusCode.InternalServerError)) return new object[0]; bool flag1 = ContentType.IsSoap(message.ContentType); if (!flag1 || flag1 && httpWebResponse != null && httpWebResponse.ContentLength == 0L) { if (num1 == 400) throw new WebException(RequestResponseUtils.CreateResponseExceptionString((WebResponse) httpWebResponse, responseStream), (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) httpWebResponse); throw new InvalidOperationException(System.Web.Services.Res.GetString("WebResponseContent", (object) message.ContentType, (object) this.HttpContentType) + Environment.NewLine + RequestResponseUtils.CreateResponseExceptionString(response, responseStream)); } else { if (message.Exception != null) throw message.Exception; int bufferSize = asyncCall || httpWebResponse == null ? 512 : RequestResponseUtils.GetBufferSize((int) httpWebResponse.ContentLength); XmlReader readerForMessage = this.GetReaderForMessage(message, bufferSize); if (readerForMessage == null) throw new InvalidOperationException(System.Web.Services.Res.GetString("WebNullReaderForMessage")); int num2 = (int) readerForMessage.MoveToContent(); int depth = readerForMessage.Depth; string encodingNs = this.EncodingNs; string namespaceUri = readerForMessage.NamespaceURI; if (namespaceUri == null || namespaceUri.Length == 0) readerForMessage.ReadStartElement("Envelope"); else if (readerForMessage.NamespaceURI == "http://schemas.xmlsoap.org/soap/envelope/") readerForMessage.ReadStartElement("Envelope", "http://schemas.xmlsoap.org/soap/envelope/"); else if (readerForMessage.NamespaceURI == "http://www.w3.org/2003/05/soap-envelope") readerForMessage.ReadStartElement("Envelope", "http://www.w3.org/2003/05/soap-envelope"); else throw new SoapException(System.Web.Services.Res.GetString("WebInvalidEnvelopeNamespace", (object) namespaceUri, (object) this.EnvelopeNs), SoapException.VersionMismatchFaultCode); int num3 = (int) readerForMessage.MoveToContent(); new SoapHeaderHandling().ReadHeaders(readerForMessage, method.outHeaderSerializer, message.Headers, method.outHeaderMappings, SoapHeaderDirection.Out | SoapHeaderDirection.Fault, namespaceUri, method.use == SoapBindingUse.Encoded ? encodingNs : (string) null, false); int num4 = (int) readerForMessage.MoveToContent(); readerForMessage.ReadStartElement("Body", namespaceUri); int num5 = (int) readerForMessage.MoveToContent(); if (readerForMessage.IsStartElement("Fault", namespaceUri)) message.Exception = this.ReadSoapException(readerForMessage); else if (method.oneWay) { readerForMessage.Skip(); message.SetParameterValues(new object[0]); } else { TraceMethod caller = Tracing.On ? new TraceMethod((object) this, "ReadResponse", new object[0]) : (TraceMethod) null; bool flag2 = method.use == SoapBindingUse.Encoded; if (Tracing.On) Tracing.Enter(Tracing.TraceId("TraceReadResponse"), caller, new TraceMethod((object) method.returnSerializer, "Deserialize", new object[2] { (object) readerForMessage, flag2 ? (object) encodingNs : (object) (string) null })); if (!flag2 && (WebServicesSection.Current.SoapEnvelopeProcessing.IsStrict || Tracing.On)) { XmlDeserializationEvents events = Tracing.On ? Tracing.GetDeserializationEvents() : RuntimeUtils.GetDeserializationEvents(); message.SetParameterValues((object[]) method.returnSerializer.Deserialize(readerForMessage, (string) null, events)); } else message.SetParameterValues((object[]) method.returnSerializer.Deserialize(readerForMessage, flag2 ? encodingNs : (string) null)); if (Tracing.On) Tracing.Exit(Tracing.TraceId("TraceReadResponse"), caller); } do ; while (depth < readerForMessage.Depth && readerForMessage.Read()); if (readerForMessage.NodeType == XmlNodeType.EndElement) readerForMessage.Read(); message.SetStage(SoapMessageStage.AfterDeserialize); message.RunExtensions(message.initializedExtensions, false); SoapHeaderHandling.SetHeaderMembers(message.Headers, (object) this, method.outHeaderMappings, SoapHeaderDirection.Out | SoapHeaderDirection.Fault, true); if (message.Exception != null) throw message.Exception; else return message.GetParameterValues(); } }
private void Serialize(SoapClientMessage message) { Stream stream = message.Stream; SoapClientMethod method = message.Method; bool isEncoded = method.use == SoapBindingUse.Encoded; string envelopeNs = this.EnvelopeNs; string encodingNs = this.EncodingNs; XmlWriter writerForMessage = this.GetWriterForMessage(message, 1024); if (writerForMessage == null) throw new InvalidOperationException(System.Web.Services.Res.GetString("WebNullWriterForMessage")); writerForMessage.WriteStartDocument(); writerForMessage.WriteStartElement("soap", "Envelope", envelopeNs); writerForMessage.WriteAttributeString("xmlns", "soap", (string) null, envelopeNs); if (isEncoded) { writerForMessage.WriteAttributeString("xmlns", "soapenc", (string) null, encodingNs); writerForMessage.WriteAttributeString("xmlns", "tns", (string) null, this.clientType.serviceNamespace); writerForMessage.WriteAttributeString("xmlns", "types", (string) null, SoapReflector.GetEncodedNamespace(this.clientType.serviceNamespace, this.clientType.serviceDefaultIsEncoded)); } writerForMessage.WriteAttributeString("xmlns", "xsi", (string) null, "http://www.w3.org/2001/XMLSchema-instance"); writerForMessage.WriteAttributeString("xmlns", "xsd", (string) null, "http://www.w3.org/2001/XMLSchema"); SoapHeaderHandling.WriteHeaders(writerForMessage, method.inHeaderSerializer, message.Headers, method.inHeaderMappings, SoapHeaderDirection.In, isEncoded, this.clientType.serviceNamespace, this.clientType.serviceDefaultIsEncoded, envelopeNs); writerForMessage.WriteStartElement("Body", envelopeNs); if (isEncoded && this.version != SoapProtocolVersion.Soap12) writerForMessage.WriteAttributeString("soap", "encodingStyle", (string) null, encodingNs); object[] parameterValues = message.GetParameterValues(); TraceMethod caller = Tracing.On ? new TraceMethod((object) this, "Serialize", new object[0]) : (TraceMethod) null; if (Tracing.On) Tracing.Enter(Tracing.TraceId("TraceWriteRequest"), caller, new TraceMethod((object) method.parameterSerializer, "Serialize", new object[4] { (object) writerForMessage, (object) parameterValues, null, isEncoded ? (object) encodingNs : (object) (string) null })); method.parameterSerializer.Serialize(writerForMessage, (object) parameterValues, (XmlSerializerNamespaces) null, isEncoded ? encodingNs : (string) null); if (Tracing.On) Tracing.Exit(Tracing.TraceId("TraceWriteRequest"), caller); writerForMessage.WriteEndElement(); writerForMessage.WriteEndElement(); writerForMessage.Flush(); message.SetStage(SoapMessageStage.AfterSerialize); message.RunExtensions(message.initializedExtensions, true); }
private object[] ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, bool asyncCall) { SoapClientMethod method = message.Method; HttpWebResponse httpWebResponse = response as HttpWebResponse; int num1 = httpWebResponse != null ? (int)httpWebResponse.StatusCode : -1; if (num1 >= 300 && num1 != 500 && num1 != 400) { throw new WebException(RequestResponseUtils.CreateResponseExceptionString((WebResponse)httpWebResponse, responseStream), (Exception)null, WebExceptionStatus.ProtocolError, (WebResponse)httpWebResponse); } message.Headers.Clear(); message.SetStream(responseStream); message.InitExtensionStreamChain(message.initializedExtensions); message.SetStage(SoapMessageStage.BeforeDeserialize); message.ContentType = response.ContentType; message.ContentEncoding = ((NameValueCollection)response.Headers)["Content-Encoding"]; message.RunExtensions(message.initializedExtensions, false); if (method.oneWay && (httpWebResponse == null || httpWebResponse.StatusCode != HttpStatusCode.InternalServerError)) { return(new object[0]); } bool flag1 = ContentType.IsSoap(message.ContentType); if (!flag1 || flag1 && httpWebResponse != null && httpWebResponse.ContentLength == 0L) { if (num1 == 400) { throw new WebException(RequestResponseUtils.CreateResponseExceptionString((WebResponse)httpWebResponse, responseStream), (Exception)null, WebExceptionStatus.ProtocolError, (WebResponse)httpWebResponse); } throw new InvalidOperationException(System.Web.Services.Res.GetString("WebResponseContent", (object)message.ContentType, (object)this.HttpContentType) + Environment.NewLine + RequestResponseUtils.CreateResponseExceptionString(response, responseStream)); } else { if (message.Exception != null) { throw message.Exception; } int bufferSize = asyncCall || httpWebResponse == null ? 512 : RequestResponseUtils.GetBufferSize((int)httpWebResponse.ContentLength); XmlReader readerForMessage = this.GetReaderForMessage(message, bufferSize); if (readerForMessage == null) { throw new InvalidOperationException(System.Web.Services.Res.GetString("WebNullReaderForMessage")); } int num2 = (int)readerForMessage.MoveToContent(); int depth = readerForMessage.Depth; string encodingNs = this.EncodingNs; string namespaceUri = readerForMessage.NamespaceURI; if (namespaceUri == null || namespaceUri.Length == 0) { readerForMessage.ReadStartElement("Envelope"); } else if (readerForMessage.NamespaceURI == "http://schemas.xmlsoap.org/soap/envelope/") { readerForMessage.ReadStartElement("Envelope", "http://schemas.xmlsoap.org/soap/envelope/"); } else if (readerForMessage.NamespaceURI == "http://www.w3.org/2003/05/soap-envelope") { readerForMessage.ReadStartElement("Envelope", "http://www.w3.org/2003/05/soap-envelope"); } else { throw new SoapException(System.Web.Services.Res.GetString("WebInvalidEnvelopeNamespace", (object)namespaceUri, (object)this.EnvelopeNs), SoapException.VersionMismatchFaultCode); } int num3 = (int)readerForMessage.MoveToContent(); new SoapHeaderHandling().ReadHeaders(readerForMessage, method.outHeaderSerializer, message.Headers, method.outHeaderMappings, SoapHeaderDirection.Out | SoapHeaderDirection.Fault, namespaceUri, method.use == SoapBindingUse.Encoded ? encodingNs : (string)null, false); int num4 = (int)readerForMessage.MoveToContent(); readerForMessage.ReadStartElement("Body", namespaceUri); int num5 = (int)readerForMessage.MoveToContent(); if (readerForMessage.IsStartElement("Fault", namespaceUri)) { message.Exception = this.ReadSoapException(readerForMessage); } else if (method.oneWay) { readerForMessage.Skip(); message.SetParameterValues(new object[0]); } else { TraceMethod caller = Tracing.On ? new TraceMethod((object)this, "ReadResponse", new object[0]) : (TraceMethod)null; bool flag2 = method.use == SoapBindingUse.Encoded; if (Tracing.On) { Tracing.Enter(Tracing.TraceId("TraceReadResponse"), caller, new TraceMethod((object)method.returnSerializer, "Deserialize", new object[2] { (object)readerForMessage, flag2 ? (object)encodingNs : (object)(string)null })); } if (!flag2 && (WebServicesSection.Current.SoapEnvelopeProcessing.IsStrict || Tracing.On)) { XmlDeserializationEvents events = Tracing.On ? Tracing.GetDeserializationEvents() : RuntimeUtils.GetDeserializationEvents(); message.SetParameterValues((object[])method.returnSerializer.Deserialize(readerForMessage, (string)null, events)); } else { message.SetParameterValues((object[])method.returnSerializer.Deserialize(readerForMessage, flag2 ? encodingNs : (string)null)); } if (Tracing.On) { Tracing.Exit(Tracing.TraceId("TraceReadResponse"), caller); } } do { ; }while (depth < readerForMessage.Depth && readerForMessage.Read()); if (readerForMessage.NodeType == XmlNodeType.EndElement) { readerForMessage.Read(); } message.SetStage(SoapMessageStage.AfterDeserialize); message.RunExtensions(message.initializedExtensions, false); SoapHeaderHandling.SetHeaderMembers(message.Headers, (object)this, method.outHeaderMappings, SoapHeaderDirection.Out | SoapHeaderDirection.Fault, true); if (message.Exception != null) { throw message.Exception; } else { return(message.GetParameterValues()); } } }
private object[] ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, bool asyncCall) { int bufferSize; SoapClientMethod method = message.Method; HttpWebResponse response2 = response as HttpWebResponse; int num = (response2 != null) ? ((int) response2.StatusCode) : -1; if (((num >= 300) && (num != 500)) && (num != 400)) { throw new WebException(RequestResponseUtils.CreateResponseExceptionString(response2, responseStream), null, WebExceptionStatus.ProtocolError, response2); } message.Headers.Clear(); message.SetStream(responseStream); message.InitExtensionStreamChain(message.initializedExtensions); message.SetStage(SoapMessageStage.BeforeDeserialize); message.ContentType = response.ContentType; message.ContentEncoding = response.Headers["Content-Encoding"]; message.RunExtensions(message.initializedExtensions, false); if (method.oneWay && ((response2 == null) || (response2.StatusCode != HttpStatusCode.InternalServerError))) { return new object[0]; } bool flag = ContentType.IsSoap(message.ContentType); if (!flag || ((flag && (response2 != null)) && (response2.ContentLength == 0L))) { if (num == 400) { throw new WebException(RequestResponseUtils.CreateResponseExceptionString(response2, responseStream), null, WebExceptionStatus.ProtocolError, response2); } throw new InvalidOperationException(System.Web.Services.Res.GetString("WebResponseContent", new object[] { message.ContentType, this.HttpContentType }) + Environment.NewLine + RequestResponseUtils.CreateResponseExceptionString(response, responseStream)); } if (message.Exception != null) { throw message.Exception; } if (asyncCall || (response2 == null)) { bufferSize = 0x200; } else { bufferSize = RequestResponseUtils.GetBufferSize((int) response2.ContentLength); } XmlReader readerForMessage = this.GetReaderForMessage(message, bufferSize); if (readerForMessage == null) { throw new InvalidOperationException(System.Web.Services.Res.GetString("WebNullReaderForMessage")); } readerForMessage.MoveToContent(); int depth = readerForMessage.Depth; string encodingNs = this.EncodingNs; string namespaceURI = readerForMessage.NamespaceURI; if ((namespaceURI == null) || (namespaceURI.Length == 0)) { readerForMessage.ReadStartElement("Envelope"); } else if (readerForMessage.NamespaceURI == "http://schemas.xmlsoap.org/soap/envelope/") { readerForMessage.ReadStartElement("Envelope", "http://schemas.xmlsoap.org/soap/envelope/"); } else { if (readerForMessage.NamespaceURI != "http://www.w3.org/2003/05/soap-envelope") { throw new SoapException(System.Web.Services.Res.GetString("WebInvalidEnvelopeNamespace", new object[] { namespaceURI, this.EnvelopeNs }), SoapException.VersionMismatchFaultCode); } readerForMessage.ReadStartElement("Envelope", "http://www.w3.org/2003/05/soap-envelope"); } readerForMessage.MoveToContent(); new SoapHeaderHandling().ReadHeaders(readerForMessage, method.outHeaderSerializer, message.Headers, method.outHeaderMappings, SoapHeaderDirection.Fault | SoapHeaderDirection.Out, namespaceURI, (method.use == SoapBindingUse.Encoded) ? encodingNs : null, false); readerForMessage.MoveToContent(); readerForMessage.ReadStartElement("Body", namespaceURI); readerForMessage.MoveToContent(); if (readerForMessage.IsStartElement("Fault", namespaceURI)) { message.Exception = this.ReadSoapException(readerForMessage); } else if (method.oneWay) { readerForMessage.Skip(); message.SetParameterValues(new object[0]); } else { TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadResponse", new object[0]) : null; bool flag2 = method.use == SoapBindingUse.Encoded; if (Tracing.On) { Tracing.Enter(Tracing.TraceId("TraceReadResponse"), caller, new TraceMethod(method.returnSerializer, "Deserialize", new object[] { readerForMessage, flag2 ? encodingNs : null })); } if (!flag2 && (WebServicesSection.Current.SoapEnvelopeProcessing.IsStrict || Tracing.On)) { XmlDeserializationEvents events = Tracing.On ? Tracing.GetDeserializationEvents() : RuntimeUtils.GetDeserializationEvents(); message.SetParameterValues((object[]) method.returnSerializer.Deserialize(readerForMessage, null, events)); } else { message.SetParameterValues((object[]) method.returnSerializer.Deserialize(readerForMessage, flag2 ? encodingNs : null)); } if (Tracing.On) { Tracing.Exit(Tracing.TraceId("TraceReadResponse"), caller); } } while ((depth < readerForMessage.Depth) && readerForMessage.Read()) { } if (readerForMessage.NodeType == XmlNodeType.EndElement) { readerForMessage.Read(); } message.SetStage(SoapMessageStage.AfterDeserialize); message.RunExtensions(message.initializedExtensions, false); SoapHeaderHandling.SetHeaderMembers(message.Headers, this, method.outHeaderMappings, SoapHeaderDirection.Fault | SoapHeaderDirection.Out, true); if (message.Exception != null) { throw message.Exception; } return message.GetParameterValues(); }
private object[] ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, bool asyncCall) { int bufferSize; SoapClientMethod method = message.Method; HttpWebResponse response2 = response as HttpWebResponse; int num = (response2 != null) ? ((int)response2.StatusCode) : -1; if (((num >= 300) && (num != 500)) && (num != 400)) { throw new WebException(RequestResponseUtils.CreateResponseExceptionString(response2, responseStream), null, WebExceptionStatus.ProtocolError, response2); } message.Headers.Clear(); message.SetStream(responseStream); message.InitExtensionStreamChain(message.initializedExtensions); message.SetStage(SoapMessageStage.BeforeDeserialize); message.ContentType = response.ContentType; message.ContentEncoding = response.Headers["Content-Encoding"]; message.RunExtensions(message.initializedExtensions, false); if (method.oneWay && ((response2 == null) || (response2.StatusCode != HttpStatusCode.InternalServerError))) { return(new object[0]); } bool flag = ContentType.IsSoap(message.ContentType); if (!flag || ((flag && (response2 != null)) && (response2.ContentLength == 0L))) { if (num == 400) { throw new WebException(RequestResponseUtils.CreateResponseExceptionString(response2, responseStream), null, WebExceptionStatus.ProtocolError, response2); } throw new InvalidOperationException(System.Web.Services.Res.GetString("WebResponseContent", new object[] { message.ContentType, this.HttpContentType }) + Environment.NewLine + RequestResponseUtils.CreateResponseExceptionString(response, responseStream)); } if (message.Exception != null) { throw message.Exception; } if (asyncCall || (response2 == null)) { bufferSize = 0x200; } else { bufferSize = RequestResponseUtils.GetBufferSize((int)response2.ContentLength); } XmlReader readerForMessage = this.GetReaderForMessage(message, bufferSize); if (readerForMessage == null) { throw new InvalidOperationException(System.Web.Services.Res.GetString("WebNullReaderForMessage")); } readerForMessage.MoveToContent(); int depth = readerForMessage.Depth; string encodingNs = this.EncodingNs; string namespaceURI = readerForMessage.NamespaceURI; if ((namespaceURI == null) || (namespaceURI.Length == 0)) { readerForMessage.ReadStartElement("Envelope"); } else if (readerForMessage.NamespaceURI == "http://schemas.xmlsoap.org/soap/envelope/") { readerForMessage.ReadStartElement("Envelope", "http://schemas.xmlsoap.org/soap/envelope/"); } else { if (readerForMessage.NamespaceURI != "http://www.w3.org/2003/05/soap-envelope") { throw new SoapException(System.Web.Services.Res.GetString("WebInvalidEnvelopeNamespace", new object[] { namespaceURI, this.EnvelopeNs }), SoapException.VersionMismatchFaultCode); } readerForMessage.ReadStartElement("Envelope", "http://www.w3.org/2003/05/soap-envelope"); } readerForMessage.MoveToContent(); new SoapHeaderHandling().ReadHeaders(readerForMessage, method.outHeaderSerializer, message.Headers, method.outHeaderMappings, SoapHeaderDirection.Fault | SoapHeaderDirection.Out, namespaceURI, (method.use == SoapBindingUse.Encoded) ? encodingNs : null, false); readerForMessage.MoveToContent(); readerForMessage.ReadStartElement("Body", namespaceURI); readerForMessage.MoveToContent(); if (readerForMessage.IsStartElement("Fault", namespaceURI)) { message.Exception = this.ReadSoapException(readerForMessage); } else if (method.oneWay) { readerForMessage.Skip(); message.SetParameterValues(new object[0]); } else { TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadResponse", new object[0]) : null; bool flag2 = method.use == SoapBindingUse.Encoded; if (Tracing.On) { Tracing.Enter(Tracing.TraceId("TraceReadResponse"), caller, new TraceMethod(method.returnSerializer, "Deserialize", new object[] { readerForMessage, flag2 ? encodingNs : null })); } if (!flag2 && (WebServicesSection.Current.SoapEnvelopeProcessing.IsStrict || Tracing.On)) { XmlDeserializationEvents events = Tracing.On ? Tracing.GetDeserializationEvents() : RuntimeUtils.GetDeserializationEvents(); message.SetParameterValues((object[])method.returnSerializer.Deserialize(readerForMessage, null, events)); } else { message.SetParameterValues((object[])method.returnSerializer.Deserialize(readerForMessage, flag2 ? encodingNs : null)); } if (Tracing.On) { Tracing.Exit(Tracing.TraceId("TraceReadResponse"), caller); } } while ((depth < readerForMessage.Depth) && readerForMessage.Read()) { } if (readerForMessage.NodeType == XmlNodeType.EndElement) { readerForMessage.Read(); } message.SetStage(SoapMessageStage.AfterDeserialize); message.RunExtensions(message.initializedExtensions, false); SoapHeaderHandling.SetHeaderMembers(message.Headers, this, method.outHeaderMappings, SoapHeaderDirection.Fault | SoapHeaderDirection.Out, true); if (message.Exception != null) { throw message.Exception; } return(message.GetParameterValues()); }