internal override void WriteReturns(object[] returnValues, Stream outputStream) { if (!this.serverMethod.oneWay) { bool isEncoded = this.serverMethod.use == SoapBindingUse.Encoded; SoapHeaderHandling.EnsureHeadersUnderstood(this.message.Headers); this.message.Headers.Clear(); SoapHeaderHandling.GetHeaderMembers(this.message.Headers, this.Target, this.serverMethod.outHeaderMappings, SoapHeaderDirection.Out, false); if (this.message.allExtensions != null) { this.message.SetExtensionStream(new SoapExtensionStream()); } this.message.InitExtensionStreamChain(this.message.allExtensions); this.message.SetStage(SoapMessageStage.BeforeSerialize); this.message.ContentType = ContentType.Compose(this.helper.HttpContentType, Encoding.UTF8); this.message.SetParameterValues(returnValues); this.message.RunExtensions(this.message.allExtensions, true); this.message.SetStream(outputStream); base.Response.ContentType = this.message.ContentType; if ((this.message.ContentEncoding != null) && (this.message.ContentEncoding.Length > 0)) { base.Response.AppendHeader("Content-Encoding", this.message.ContentEncoding); } XmlWriter writerForMessage = this.GetWriterForMessage(this.message, 0x400); if (writerForMessage == null) { throw new InvalidOperationException(System.Web.Services.Res.GetString("WebNullWriterForMessage")); } writerForMessage.WriteStartDocument(); writerForMessage.WriteStartElement("soap", "Envelope", this.helper.EnvelopeNs); writerForMessage.WriteAttributeString("xmlns", "soap", null, this.helper.EnvelopeNs); if (isEncoded) { writerForMessage.WriteAttributeString("xmlns", "soapenc", null, this.helper.EncodingNs); writerForMessage.WriteAttributeString("xmlns", "tns", null, this.serverType.serviceNamespace); writerForMessage.WriteAttributeString("xmlns", "types", null, SoapReflector.GetEncodedNamespace(this.serverType.serviceNamespace, this.serverType.serviceDefaultIsEncoded)); } if (this.serverMethod.rpc && (this.version == SoapProtocolVersion.Soap12)) { writerForMessage.WriteAttributeString("xmlns", "rpc", null, "http://www.w3.org/2003/05/soap-rpc"); } writerForMessage.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); writerForMessage.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema"); SoapHeaderHandling.WriteHeaders(writerForMessage, this.serverMethod.outHeaderSerializer, this.message.Headers, this.serverMethod.outHeaderMappings, SoapHeaderDirection.Out, isEncoded, this.serverType.serviceNamespace, this.serverType.serviceDefaultIsEncoded, this.helper.EnvelopeNs); writerForMessage.WriteStartElement("Body", this.helper.EnvelopeNs); if (isEncoded && (this.version != SoapProtocolVersion.Soap12)) { writerForMessage.WriteAttributeString("soap", "encodingStyle", null, this.helper.EncodingNs); } TraceMethod caller = Tracing.On ? new TraceMethod(this, "WriteReturns", new object[0]) : null; if (Tracing.On) { object[] args = new object[4]; args[0] = writerForMessage; args[1] = returnValues; args[3] = isEncoded ? this.helper.EncodingNs : null; Tracing.Enter(Tracing.TraceId("TraceWriteResponse"), caller, new TraceMethod(this.serverMethod.returnSerializer, "Serialize", args)); } this.serverMethod.returnSerializer.Serialize(writerForMessage, returnValues, null, isEncoded ? this.helper.EncodingNs : null); if (Tracing.On) { Tracing.Exit(Tracing.TraceId("TraceWriteResponse"), caller); } writerForMessage.WriteEndElement(); writerForMessage.WriteEndElement(); writerForMessage.Flush(); this.message.SetStage(SoapMessageStage.AfterSerialize); this.message.RunExtensions(this.message.allExtensions, true); } }
internal override void WriteReturns(object[] returnValues, Stream outputStream) { if (serverMethod.oneWay) { return; } bool isEncoded = serverMethod.use == SoapBindingUse.Encoded; SoapHeaderHandling.EnsureHeadersUnderstood(message.Headers); message.Headers.Clear(); SoapHeaderHandling.GetHeaderMembers(message.Headers, this.Target, serverMethod.outHeaderMappings, SoapHeaderDirection.Out, false); if (message.allExtensions != null) { message.SetExtensionStream(new SoapExtensionStream()); } message.InitExtensionStreamChain(message.allExtensions); message.SetStage(SoapMessageStage.BeforeSerialize); message.ContentType = ContentType.Compose(helper.HttpContentType, Encoding.UTF8); message.SetParameterValues(returnValues); message.RunExtensions(message.allExtensions); message.SetStream(outputStream); Response.ContentType = message.ContentType; if (message.ContentEncoding != null && message.ContentEncoding.Length > 0) { Response.AppendHeader(ContentType.ContentEncoding, message.ContentEncoding); } StreamWriter sw = new StreamWriter(message.Stream, new UTF8Encoding(false), 128); XmlTextWriter writer = isEncoded && message.Headers.Count > 0 ? new XmlSpecialTextWriter(sw, helper.Version) : new XmlTextWriter(sw); writer.WriteStartDocument(); writer.WriteStartElement("soap", Soap.Envelope, helper.EnvelopeNs); writer.WriteAttributeString("xmlns", "soap", null, helper.EnvelopeNs); if (isEncoded) { writer.WriteAttributeString("xmlns", "soapenc", null, helper.EncodingNs); writer.WriteAttributeString("xmlns", "tns", null, serverType.serviceNamespace); writer.WriteAttributeString("xmlns", "types", null, SoapReflector.GetEncodedNamespace(serverType.serviceNamespace, serverType.serviceDefaultIsEncoded)); } if (serverMethod.rpc && version == SoapProtocolVersion.Soap12) { writer.WriteAttributeString("xmlns", "rpc", null, Soap12.RpcNamespace); } writer.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace); writer.WriteAttributeString("xmlns", "xsd", null, XmlSchema.Namespace); SoapHeaderHandling.WriteHeaders(writer, serverMethod.outHeaderSerializer, message.Headers, serverMethod.outHeaderMappings, SoapHeaderDirection.Out, isEncoded, serverType.serviceNamespace, serverType.serviceDefaultIsEncoded, helper.EnvelopeNs); writer.WriteStartElement(Soap.Body, helper.EnvelopeNs); if (isEncoded) { writer.WriteAttributeString("soap", Soap.EncodingStyle, null, helper.EncodingNs); } // SOAP12: not using encodingStyle //serverMethod.returnSerializer.Serialize(writer, returnValues, null, isEncoded ? helper.EncodingNs : null); serverMethod.returnSerializer.Serialize(writer, returnValues, null); writer.WriteEndElement(); writer.WriteEndElement(); writer.Flush(); message.SetStage(SoapMessageStage.AfterSerialize); message.RunExtensions(message.allExtensions); }