public static void SetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client) { bool[] flagArray = new bool[headers.Count]; if (mappings != null) { for (int j = 0; j < mappings.Length; j++) { SoapHeaderMapping mapping = mappings[j]; if ((mapping.direction & direction) != 0) { if (mapping.repeats) { ArrayList list = new ArrayList(); for (int k = 0; k < headers.Count; k++) { SoapHeader header = headers[k]; if (!flagArray[k] && mapping.headerType.IsAssignableFrom(header.GetType())) { list.Add(header); flagArray[k] = true; } } MemberHelper.SetValue(mapping.memberInfo, target, list.ToArray(mapping.headerType)); } else { bool flag = false; for (int m = 0; m < headers.Count; m++) { SoapHeader header2 = headers[m]; if (!flagArray[m] && mapping.headerType.IsAssignableFrom(header2.GetType())) { if (flag) { header2.DidUnderstand = false; } else { flag = true; MemberHelper.SetValue(mapping.memberInfo, target, header2); flagArray[m] = true; } } } } } } } for (int i = 0; i < flagArray.Length; i++) { if (!flagArray[i]) { SoapHeader header3 = headers[i]; if (header3.MustUnderstand && !header3.DidUnderstand) { throw new SoapHeaderException(System.Web.Services.Res.GetString("WebCannotUnderstandHeader", new object[] { GetHeaderElementName(header3) }), new XmlQualifiedName("MustUnderstand", "http://schemas.xmlsoap.org/soap/envelope/")); } } } }
public static void WriteUnknownHeaders( XmlWriter writer, SoapHeaderCollection headers, string envelopeNS) { throw new NotImplementedException(); }
public static void GetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client) { if ((mappings != null) && (mappings.Length != 0)) { for (int i = 0; i < mappings.Length; i++) { SoapHeaderMapping mapping = mappings[i]; if ((mapping.direction & direction) != 0) { object obj2 = MemberHelper.GetValue(mapping.memberInfo, target); if (mapping.repeats) { object[] objArray = (object[]) obj2; if (objArray != null) { for (int j = 0; j < objArray.Length; j++) { if (objArray[j] != null) { headers.Add((SoapHeader) objArray[j]); } } } } else if (obj2 != null) { headers.Add((SoapHeader) obj2); } } } } }
public static void GetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client) { if ((mappings != null) && (mappings.Length != 0)) { for (int i = 0; i < mappings.Length; i++) { SoapHeaderMapping mapping = mappings[i]; if ((mapping.direction & direction) != 0) { object obj2 = MemberHelper.GetValue(mapping.memberInfo, target); if (mapping.repeats) { object[] objArray = (object[])obj2; if (objArray != null) { for (int j = 0; j < objArray.Length; j++) { if (objArray[j] != null) { headers.Add((SoapHeader)objArray[j]); } } } } else if (obj2 != null) { headers.Add((SoapHeader)obj2); } } } } }
public static void WriteUnknownHeaders(XmlWriter writer, SoapHeaderCollection headers, string envelopeNS) { bool flag = true; foreach (SoapHeader header in headers) { SoapUnknownHeader header2 = header as SoapUnknownHeader; if (header2 != null) { if (flag) { writer.WriteStartElement("Header", envelopeNS); flag = false; } if (header2.Element != null) { header2.Element.WriteTo(writer); } } } if (!flag) { writer.WriteEndElement(); } }
internal static void WriteUnknownHeaders(XmlWriter writer, SoapHeaderCollection headers, string envelopeNs) { bool first = true; foreach (SoapHeader header in headers) { SoapUnknownHeader unknown = header as SoapUnknownHeader; if (unknown != null) { if (first) { writer.WriteStartElement(Soap.Header, envelopeNs); first = false; } if (unknown.Element != null) { unknown.Element.WriteTo(writer); } } } if (!first) { writer.WriteEndElement(); // </soap:Header> } }
internal static void GetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client) { for (int i = 0; i < mappings.Length; i++) { SoapHeaderMapping mapping = mappings[i]; if ((mapping.direction & direction) == 0) { continue; } object value = MemberHelper.GetValue(mapping.memberInfo, target); if (mapping.repeats) { object[] values = (object[])value; if (values == null) { continue; } for (int j = 0; j < values.Length; j++) { if (values[j] != null) { headers.Add((SoapHeader)values[j]); } } } else { if (value != null) { headers.Add((SoapHeader)value); } } } }
public static void SetHeaderMembers ( SoapHeaderCollection headers, object target, SoapHeaderMapping [] mappings, SoapHeaderDirection direction, bool client) { throw new NotImplementedException (); }
public static void SetHeaderMembers( SoapHeaderCollection headers, object target, SoapHeaderMapping [] mappings, SoapHeaderDirection direction, bool client) { throw new NotImplementedException(); }
public static void EnsureHeadersUnderstood(SoapHeaderCollection headers) { for (int i = 0; i < headers.Count; i++) { SoapHeader header = headers[i]; if (header.MustUnderstand && !header.DidUnderstand) { throw new SoapHeaderException(System.Web.Services.Res.GetString("WebCannotUnderstandHeader", new object[] { GetHeaderElementName(header) }), new XmlQualifiedName("MustUnderstand", "http://schemas.xmlsoap.org/soap/envelope/")); } } }
internal static void EnsureHeadersUnderstood(SoapHeaderCollection headers) { for (int i = 0; i < headers.Count; i++) { SoapHeader header = headers[i]; if (header.MustUnderstand && !header.DidUnderstand) { throw new SoapHeaderException(Res.GetString(Res.WebCannotUnderstandHeader, GetHeaderElementName(header)), new XmlQualifiedName(Soap.MustUnderstandCode, Soap.Namespace)); } } }
public string ReadHeaders( XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping [] mappings, SoapHeaderDirection direction, string envelopeNS, string encodingStyle, bool checkRequiredHeaders) { throw new NotImplementedException(); }
public static void WriteHeaders( XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping [] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNS, bool serviceDefaultIsEncoded, string envelopeNS) { throw new NotImplementedException(); }
public static void WriteHeaders ( XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping [] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNS, bool serviceDefaultIsEncoded, string envelopeNS) { throw new NotImplementedException (); }
static SoapHeaderCollection ReadHeaders(XmlTextReader xmlReader, XmlSerializer headerSerializer, string ns) { SoapHeaderCollection headers = null; while (!(xmlReader.NodeType == XmlNodeType.Element && xmlReader.LocalName == "Body" && xmlReader.NamespaceURI == ns)) { if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.LocalName == "Header" && xmlReader.NamespaceURI == ns && !xmlReader.IsEmptyElement && headerSerializer != null) { xmlReader.ReadStartElement(); xmlReader.MoveToContent(); HeaderSerializationHelper uh = new HeaderSerializationHelper(headerSerializer); headers = uh.Deserialize(xmlReader); while (xmlReader.NodeType != XmlNodeType.EndElement) { xmlReader.Skip(); } xmlReader.ReadEndElement(); } else { xmlReader.Skip(); } } if (headers != null) { return(headers); } else { return(new SoapHeaderCollection()); } }
public object[] GetHeaderValueArray(SoapHeaderDirection dir, SoapHeaderCollection headers) { HeaderInfo[] headerInfos = GetHeaders(dir); if (headerInfos == null) { return(null); } object[] hs = new object [headerInfos.Length]; for (int n = 0; n < headers.Count; n++) { SoapHeader h = headers[n]; Type t = h.GetType(); for (int i = 0; i < headerInfos.Length; i++) { if (headerInfos [i].HeaderType == t) { hs [i] = h; } } } return(hs); }
public string ReadHeaders ( XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping [] mappings, SoapHeaderDirection direction, string envelopeNS, string encodingStyle, bool checkRequiredHeaders) { throw new NotImplementedException (); }
public static void GetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client) { if (mappings == null || mappings.Length == 0) return; for (int i = 0; i < mappings.Length; i++) { SoapHeaderMapping mapping = mappings[i]; if ((mapping.direction & direction) == 0) continue; object value = MemberHelper.GetValue(mapping.memberInfo, target); if (mapping.repeats) { object[] values = (object[])value; if (values == null) continue; for (int j = 0; j < values.Length; j++) { if (values[j] != null) headers.Add((SoapHeader)values[j]); } } else { if (value != null) headers.Add((SoapHeader)value); } } }
internal SoapMessage(Stream stream, SoapException exception) { this.exception = exception; this.stream = stream; headers = new SoapHeaderCollection(); }
public static void WriteUnknownHeaders ( XmlWriter writer, SoapHeaderCollection headers, string envelopeNS) { throw new NotImplementedException (); }
public HeaderSerializationHelper (XmlSerializer headerSerializer) { this.headers = new SoapHeaderCollection (); this.headerSerializer = headerSerializer; }
internal void SetHeaders(SoapHeaderCollection headers) { this.headers = headers; }
static SoapHeaderCollection ReadHeaders (SoapTypeStubInfo typeStubInfo, SoapBindingUse methodUse, XmlTextReader xmlReader) { SoapHeaderCollection headers = new SoapHeaderCollection (); while (! (xmlReader.NodeType == XmlNodeType.Element && xmlReader.LocalName == "Body" && xmlReader.NamespaceURI == WebServiceHelper.SoapEnvelopeNamespace)) { if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.LocalName == "Header" && xmlReader.NamespaceURI == WebServiceHelper.SoapEnvelopeNamespace && !xmlReader.IsEmptyElement) { xmlReader.ReadStartElement (); xmlReader.MoveToContent (); while (xmlReader.NodeType != XmlNodeType.Element && xmlReader.NodeType != XmlNodeType.EndElement) xmlReader.Skip (); xmlReader.MoveToContent (); if (xmlReader.NodeType == XmlNodeType.Element) { XmlQualifiedName qname = new XmlQualifiedName (xmlReader.LocalName, xmlReader.NamespaceURI); XmlSerializer headerSerializer = typeStubInfo.GetHeaderSerializer (qname, methodUse); if (headerSerializer != null) { SoapHeader header = (SoapHeader) headerSerializer.Deserialize (xmlReader); headers.Add (header); } else { XmlDocument doc = new XmlDocument (); XmlElement elem = (XmlElement) doc.ReadNode (xmlReader); headers.Add (new SoapUnknownHeader (elem)); } } while (xmlReader.NodeType != XmlNodeType.EndElement) xmlReader.Skip (); xmlReader.ReadEndElement (); } else xmlReader.Skip (); } return headers; }
public static void ReadSoapMessage(XmlTextReader xmlReader, SoapMethodStubInfo method, SoapHeaderDirection dir, bool soap12, out object body, out SoapHeaderCollection headers) { XmlSerializer bodySerializer = method.GetBodySerializer(dir, false); // no need to worry about soap12 arg since no call for Fault anyways here. XmlSerializer headerSerializer = method.GetHeaderSerializer(dir); ReadSoapMessage(xmlReader, bodySerializer, headerSerializer, soap12, out body, out headers); }
public static void WriteSoapMessage (XmlTextWriter xtw, SoapTypeStubInfo info, SoapBindingUse methodUse, XmlSerializer bodySerializer, object bodyContent, SoapHeaderCollection headers) { xtw.WriteStartDocument (); xtw.WriteStartElement ("soap", "Envelope", WebServiceHelper.SoapEnvelopeNamespace); xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace); xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace); // Serialize headers if (headers != null) { foreach (SoapHeader header in headers) { XmlSerializer ser = info.GetHeaderSerializer (header.GetType(), methodUse); xtw.WriteStartElement ("soap", "Header", WebServiceHelper.SoapEnvelopeNamespace); ser.Serialize (xtw, header); xtw.WriteEndElement (); } } // Serialize body xtw.WriteStartElement ("soap", "Body", WebServiceHelper.SoapEnvelopeNamespace); if (methodUse == SoapBindingUse.Encoded) xtw.WriteAttributeString ("encodingStyle", WebServiceHelper.SoapEnvelopeNamespace, "http://schemas.xmlsoap.org/soap/encoding/"); bodySerializer.Serialize (xtw, bodyContent); xtw.WriteEndElement (); xtw.WriteEndElement (); xtw.Flush (); }
public static void ReadSoapMessage (XmlTextReader xmlReader, SoapTypeStubInfo typeStubInfo, SoapBindingUse methodUse, XmlSerializer bodySerializer, out object body, out SoapHeaderCollection headers) { xmlReader.MoveToContent (); xmlReader.ReadStartElement ("Envelope", WebServiceHelper.SoapEnvelopeNamespace); headers = ReadHeaders (typeStubInfo, methodUse, xmlReader); xmlReader.MoveToContent (); xmlReader.ReadStartElement ("Body", WebServiceHelper.SoapEnvelopeNamespace); xmlReader.MoveToContent (); if (xmlReader.LocalName == "Fault" && xmlReader.NamespaceURI == SoapEnvelopeNamespace) bodySerializer = Fault.Serializer; body = bodySerializer.Deserialize (xmlReader); }
static void ReadSoapMessage(XmlTextReader xmlReader, object soapMethodStubInfo, SoapHeaderDirection dir, bool soap12, out object body, out SoapHeaderCollection headers) { XmlSerializer bodySerializer = (XmlSerializer)ReflectionHelper.ExecuteMethod(soapMethodStubInfo, "GetBodySerializer", null, dir, false); XmlSerializer headerSerializer = (XmlSerializer)ReflectionHelper.ExecuteMethod(soapMethodStubInfo, "GetHeaderSerializer", null, dir); try { xmlReader.MoveToContent(); string ns = xmlReader.NamespaceURI; switch (ns) { case SoapEnvelopeNamespace: break; default: throw new SoapException(String.Format("SOAP version mismatch. Namespace '{0}' is not supported in this runtime profile.", ns), VersionMismatchFaultCode(soap12)); } xmlReader.ReadStartElement("Envelope", ns); headers = (SoapHeaderCollection)ReflectionHelper.ExecuteStaticMethod(WebServiceHelperType, "ReadHeaders", null, xmlReader, headerSerializer, ns); xmlReader.MoveToContent(); xmlReader.ReadStartElement("Body", ns); xmlReader.MoveToContent(); //we have a SOAP error, deserialize... if (xmlReader.LocalName == "Fault" && xmlReader.NamespaceURI == ns) { if (ns == Soap12EnvelopeNamespace) { bodySerializer = Fault12Serializer; } else { bodySerializer = FaultSerializer; } } body = bodySerializer.Deserialize(xmlReader); //asd } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } finally { } }
static void WriteSoapMessage(XmlTextWriter xtw, Object methodStubInfo, SoapHeaderDirection dir, object bodyContent, SoapHeaderCollection headers, bool soap12) { SoapBindingUse use = (SoapBindingUse)ReflectionHelper.GetFieldValue(methodStubInfo, "Use"); SoapBindingUse methodUse = dir == SoapHeaderDirection.Fault ? SoapBindingUse.Literal : use; XmlSerializer bodySerializer = (XmlSerializer)ReflectionHelper.ExecuteMethod(methodStubInfo, "GetBodySerializer", null, dir, soap12); XmlSerializer headerSerializer = (XmlSerializer)ReflectionHelper.ExecuteMethod(methodStubInfo, "GetHeaderSerializer", null, dir); object[] headerArray = (object[])ReflectionHelper.ExecuteMethod(methodStubInfo, "GetHeaderValueArray", null, dir, headers); string ns = soap12 ? Soap12EnvelopeNamespace : SoapEnvelopeNamespace; string encNS = soap12 ? Soap12EncodingNamespace : SoapEncodingNamespace; xtw.WriteStartDocument(); xtw.WriteStartElement("soap", "Envelope", ns); xtw.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace); xtw.WriteAttributeString("xmlns", "xsd", null, XmlSchema.Namespace); // Serialize headers if (headerArray != null) { xtw.WriteStartElement("soap", "Header", ns); headerSerializer.Serialize(xtw, headerArray); xtw.WriteEndElement(); } // Serialize body xtw.WriteStartElement("soap", "Body", ns); if (methodUse == SoapBindingUse.Encoded) { xtw.WriteAttributeString("encodingStyle", ns, encNS); } bodySerializer.Serialize(xtw, bodyContent); xtw.WriteEndElement(); xtw.WriteEndElement(); xtw.Flush(); }
object[] DeserializeResponse(Stream responseBodyStream, HttpStatusCode statusCode, string contentType, SoapClientMessage message, SoapExtension[] extensions) { try { var msi = ReflectionHelper.GetFieldValue(message, "MethodStubInfo"); //web exception if (!(statusCode == HttpStatusCode.Accepted || statusCode == HttpStatusCode.OK || statusCode == HttpStatusCode.InternalServerError)) { string msg = "The request failed with HTTP status {0}: {1}"; msg = String.Format(msg, (int)statusCode, statusCode); throw new WebException(msg, null, WebExceptionStatus.ProtocolError, null); } //no response to process if (message.OneWay && responseBodyStream.Length <= 0 && (statusCode == HttpStatusCode.Accepted || statusCode == HttpStatusCode.OK)) { return(new object[0]); } string ctype; Encoding encoding = GetContentEncoding(contentType, out ctype); ctype = ctype.ToLower(CultureInfo.InvariantCulture); if (ctype != "text/xml") { ReflectionHelper.ExecuteStaticMethod(WebServiceHelperType, "InvalidOperation", null, String.Format("Not supported Content-Type in the response: '{0}'", ctype), null, encoding); } message.ContentType = ctype; message.ContentEncoding = encoding.WebName; if (extensions != null) { responseBodyStream = (Stream)ReflectionHelper.ExecuteStaticMethod(SoapExtensionType, "ExecuteChainStream", null, extensions, responseBodyStream); ReflectionHelper.ExecuteMethod(message, "SetStage", null, SoapMessageStage.BeforeDeserialize); ReflectionHelper.ExecuteStaticMethod(SoapExtensionType, "ExecuteProcessMessage", null, extensions, message, responseBodyStream, true); } // Deserialize the response SoapHeaderCollection headers = null; object content = null; var isSoap12Bool = ReflectionHelper.GetPropertyValue(message, "IsSoap12"); var methodStubInfo = ReflectionHelper.GetFieldValue(message, "MethodStubInfo"); var methodStubInfoHeaders = ReflectionHelper.GetFieldValue(methodStubInfo, "Headers"); using (StreamReader reader = new StreamReader(responseBodyStream, encoding, false)) { using (XmlTextReader xml_reader = new XmlTextReader(reader)) { // Type[] methodTypes = new Type[] { // typeof(XmlTextReader), // MethodStubInfoType, // typeof(SoapHeaderDirection), // typeof(bool), // typeof(object), // typeof(SoapHeaderCollection) // }; ReadSoapMessage(xml_reader, msi, SoapHeaderDirection.Out, (bool)isSoap12Bool, out content, out headers); //(XmlTextWriter)ReflectionHelper.ExecuteStaticMethod (webServiceHelperType, "ReadSoapMessage", methodTypes, xml_reader, msi, SoapHeaderDirection.Out, isSoap12Bool, content, headers); } } if (content.GetType() == FaultType) { object fault = content; object faultstring = ReflectionHelper.GetFieldValue(fault, "faultstring"); object faultcode = ReflectionHelper.GetFieldValue(fault, "faultcode"); object faultactor = ReflectionHelper.GetFieldValue(fault, "faultactor"); object faultdetail = ReflectionHelper.GetFieldValue(fault, "detail"); SoapException ex = new SoapException((string)faultstring, (XmlQualifiedName)faultcode, (string)faultactor, (XmlNode)faultdetail); ReflectionHelper.ExecuteMethod(message, "SetException", ex); } else { ReflectionHelper.SetPropertyValue(message, "OutParameters", (object[])content); } ReflectionHelper.ExecuteMethod(message, "SetHeaders", null, headers); ReflectionHelper.ExecuteMethod(message, "UpdateHeaderValues", null, this, methodStubInfoHeaders); if (extensions != null) { ReflectionHelper.ExecuteMethod(message, "SetStage", SoapMessageStage.AfterDeserialize); ReflectionHelper.ExecuteStaticMethod(SoapExtensionType, "ExecuteProcessMessage", null, extensions, message, responseBodyStream, true); } if (message.Exception == null) { var outParameters = ReflectionHelper.GetPropertyValue(message, "OutParameters"); return((object[])outParameters); } else { Console.WriteLine(message.Exception.Message); throw message.Exception; } } catch (Exception ex) { Console.WriteLine(ex.Message); throw ex; } finally { } }
public static void EnsureHeadersUnderstood(SoapHeaderCollection headers) { for (int i = 0; i < headers.Count; i++) { SoapHeader header = headers[i]; if (header.MustUnderstand && !header.DidUnderstand) { throw new SoapHeaderException(Res.GetString(Res.WebCannotUnderstandHeader, GetHeaderElementName(header)), new XmlQualifiedName(Soap.Code.MustUnderstand, Soap.Namespace)); } } }
public static void EnsureHeadersUnderstood (SoapHeaderCollection headers) { throw new NotImplementedException (); }
public static void WriteSoapMessage(XmlTextWriter xtw, SoapMethodStubInfo method, SoapHeaderDirection dir, object bodyContent, SoapHeaderCollection headers, bool soap12) { SoapBindingUse methodUse = dir == SoapHeaderDirection.Fault ? SoapBindingUse.Literal : method.Use; XmlSerializer bodySerializer = method.GetBodySerializer(dir, soap12); XmlSerializer headerSerializer = method.GetHeaderSerializer(dir); object[] headerArray = method.GetHeaderValueArray(dir, headers); WriteSoapMessage(xtw, methodUse, bodySerializer, headerSerializer, bodyContent, headerArray, soap12); }
internal void SetHeaders (SoapHeaderCollection headers) { this.headers = headers; }
public static void ReadSoapMessage(XmlTextReader xmlReader, XmlSerializer bodySerializer, XmlSerializer headerSerializer, bool soap12, out object body, out SoapHeaderCollection headers) { xmlReader.MoveToContent(); string ns = xmlReader.NamespaceURI; switch (ns) { #if NET_2_0 case WebServiceHelper.Soap12EnvelopeNamespace: #endif case WebServiceHelper.SoapEnvelopeNamespace: break; default: throw new SoapException(String.Format("SOAP version mismatch. Namespace '{0}' is not supported in this runtime profile.", ns), VersionMismatchFaultCode(soap12)); } xmlReader.ReadStartElement("Envelope", ns); headers = ReadHeaders(xmlReader, headerSerializer, ns); xmlReader.MoveToContent(); xmlReader.ReadStartElement("Body", ns); xmlReader.MoveToContent(); if (xmlReader.LocalName == "Fault" && xmlReader.NamespaceURI == ns) { bodySerializer = ns == Soap12EnvelopeNamespace ? Soap12Fault.Serializer : Fault.Serializer; } body = bodySerializer.Deserialize(xmlReader); }
internal SoapMessage (Stream stream, SoapException exception) { this.exception = exception; this.stream = stream; headers = new SoapHeaderCollection (); }
public HeaderSerializationHelper(XmlSerializer headerSerializer) { this.headers = new SoapHeaderCollection(); this.headerSerializer = headerSerializer; }
internal static void WriteHeaders(XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNs, bool serviceDefaultIsEncoded, string envelopeNs) { if (headers.Count == 0) { return; } if (isEncoded && writer is XmlSpecialTextWriter) { ((XmlSpecialTextWriter)writer).EncodeIds = true; } writer.WriteStartElement(Soap.Header, envelopeNs); // SOAP12: always soap 1.1, not using encodingStyle; //SoapProtocolVersion version; SoapProtocolVersion version = SoapProtocolVersion.Soap11; // SOAP12: not using encodingStyle /*string encodingStyle; * if (envelopeNs == Soap12.Namespace) { * version = SoapProtocolVersion.Soap12; * encodingStyle = Soap12.Encoding; * } * else { * version = SoapProtocolVersion.Soap11; * encodingStyle = Soap.Encoding; * }*/ int unknownHeaderCount = 0; ArrayList otherHeaders = new ArrayList(); SoapHeader[] headerArray = new SoapHeader[mappings.Length]; bool[] headerSet = new bool[headerArray.Length]; for (int i = 0; i < headers.Count; i++) { SoapHeader header = headers[i]; if (header == null) { continue; } int headerPosition; header.version = version; if (header is SoapUnknownHeader) { otherHeaders.Add(header); unknownHeaderCount++; } else if ((headerPosition = FindMapping(mappings, header, direction)) >= 0 && !headerSet[headerPosition]) { headerArray[headerPosition] = header; headerSet[headerPosition] = true; } else { otherHeaders.Add(header); } } int otherHeaderCount = otherHeaders.Count - unknownHeaderCount; if (isEncoded && otherHeaderCount > 0) { SoapHeader[] newHeaderArray = new SoapHeader[mappings.Length + otherHeaderCount]; headerArray.CopyTo(newHeaderArray, 0); // fill in the non-statically known headers (otherHeaders) starting after the statically-known ones int count = mappings.Length; for (int i = 0; i < otherHeaders.Count; i++) { if (!(otherHeaders[i] is SoapUnknownHeader)) { newHeaderArray[count++] = (SoapHeader)otherHeaders[i]; } } headerArray = newHeaderArray; } // SOAP12: not using encodingStyle //serializer.Serialize(writer, headerArray, null, isEncoded ? encodingStyle : null); serializer.Serialize(writer, headerArray, null); foreach (SoapHeader header in otherHeaders) { if (header is SoapUnknownHeader) { SoapUnknownHeader unknown = (SoapUnknownHeader)header; if (unknown.Element != null) { unknown.Element.WriteTo(writer); } } else if (!isEncoded) // encoded headers already appended to members mapping { string ns = SoapReflector.GetLiteralNamespace(defaultNs, serviceDefaultIsEncoded); new XmlSerializer(header.GetType(), ns).Serialize(writer, header); } } // reset the soap version for (int i = 0; i < headers.Count; i++) { SoapHeader header = headers[i]; if (header != null) { header.version = SoapProtocolVersion.Default; } } writer.WriteEndElement(); writer.Flush(); if (isEncoded && writer is XmlSpecialTextWriter) { ((XmlSpecialTextWriter)writer).EncodeIds = false; } }
internal SoapMessage() { headers = new SoapHeaderCollection(); }
internal static void SetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client) { bool[] headerHandled = new bool[headers.Count]; for (int i = 0; i < mappings.Length; i++) { SoapHeaderMapping mapping = mappings[i]; if ((mapping.direction & direction) == 0) { continue; } if (mapping.repeats) { ArrayList list = new ArrayList(); for (int j = 0; j < headers.Count; j++) { SoapHeader header = headers[j]; if (headerHandled[j]) { continue; } if (mapping.headerType.IsAssignableFrom(header.GetType())) { list.Add(header); headerHandled[j] = true; } } MemberHelper.SetValue(mapping.memberInfo, target, list.ToArray(mapping.headerType)); } else { bool handled = false; for (int j = 0; j < headers.Count; j++) { SoapHeader header = headers[j]; if (headerHandled[j]) { continue; } if (mapping.headerType.IsAssignableFrom(header.GetType())) { if (handled) { header.DidUnderstand = false; continue; } handled = true; MemberHelper.SetValue(mapping.memberInfo, target, header); headerHandled[j] = true; } } } } if (client) { for (int i = 0; i < headerHandled.Length; i++) { if (!headerHandled[i]) { SoapHeader header = headers[i]; if (header.MustUnderstand && !header.DidUnderstand) { throw new SoapHeaderException(Res.GetString(Res.WebCannotUnderstandHeader, GetHeaderElementName(header)), new XmlQualifiedName(Soap.MustUnderstandCode, Soap.Namespace)); } } } } }
public static void WriteHeaders(XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNS, bool serviceDefaultIsEncoded, string envelopeNS) { if (headers.Count != 0) { SoapProtocolVersion version; string str; writer.WriteStartElement("Header", envelopeNS); if (envelopeNS == "http://www.w3.org/2003/05/soap-envelope") { version = SoapProtocolVersion.Soap12; str = "http://www.w3.org/2003/05/soap-encoding"; } else { version = SoapProtocolVersion.Soap11; str = "http://schemas.xmlsoap.org/soap/encoding/"; } int num = 0; ArrayList list = new ArrayList(); SoapHeader[] o = new SoapHeader[mappings.Length]; bool[] flagArray = new bool[o.Length]; for (int i = 0; i < headers.Count; i++) { SoapHeader header = headers[i]; if (header != null) { header.version = version; if (header is SoapUnknownHeader) { list.Add(header); num++; } else { int num3; if (((num3 = FindMapping(mappings, header, direction)) >= 0) && !flagArray[num3]) { o[num3] = header; flagArray[num3] = true; } else { list.Add(header); } } } } int num4 = list.Count - num; if (isEncoded && (num4 > 0)) { SoapHeader[] array = new SoapHeader[mappings.Length + num4]; o.CopyTo(array, 0); int length = mappings.Length; for (int k = 0; k < list.Count; k++) { if (!(list[k] is SoapUnknownHeader)) { array[length++] = (SoapHeader) list[k]; } } o = array; } TraceMethod caller = Tracing.On ? new TraceMethod(typeof(SoapHeaderHandling), "WriteHeaders", new object[0]) : null; if (Tracing.On) { object[] args = new object[5]; args[0] = writer; args[1] = o; args[3] = isEncoded ? str : null; args[4] = "h_"; Tracing.Enter(Tracing.TraceId("TraceWriteHeaders"), caller, new TraceMethod(serializer, "Serialize", args)); } serializer.Serialize(writer, o, null, isEncoded ? str : null, "h_"); if (Tracing.On) { Tracing.Exit(Tracing.TraceId("TraceWriteHeaders"), caller); } foreach (SoapHeader header2 in list) { if (header2 is SoapUnknownHeader) { SoapUnknownHeader header3 = (SoapUnknownHeader) header2; if (header3.Element != null) { header3.Element.WriteTo(writer); } } else if (!isEncoded) { string literalNamespace = SoapReflector.GetLiteralNamespace(defaultNS, serviceDefaultIsEncoded); XmlSerializer target = new XmlSerializer(header2.GetType(), literalNamespace); if (Tracing.On) { Tracing.Enter(Tracing.TraceId("TraceWriteHeaders"), caller, new TraceMethod(target, "Serialize", new object[] { writer, header2 })); } target.Serialize(writer, header2); if (Tracing.On) { Tracing.Exit(Tracing.TraceId("TraceWriteHeaders"), caller); } } } for (int j = 0; j < headers.Count; j++) { SoapHeader header4 = headers[j]; if (header4 != null) { header4.version = SoapProtocolVersion.Default; } } writer.WriteEndElement(); writer.Flush(); } }
public static void ReadSoapMessage (XmlTextReader xmlReader, XmlSerializer bodySerializer, XmlSerializer headerSerializer, bool soap12, out object body, out SoapHeaderCollection headers) { xmlReader.MoveToContent (); string ns = xmlReader.NamespaceURI; switch (ns) { #if NET_2_0 case WebServiceHelper.Soap12EnvelopeNamespace: #endif case WebServiceHelper.SoapEnvelopeNamespace: break; default: throw new SoapException (String.Format ("SOAP version mismatch. Namespace '{0}' is not supported in this runtime profile.", ns), VersionMismatchFaultCode (soap12)); } xmlReader.ReadStartElement ("Envelope", ns); headers = ReadHeaders (xmlReader, headerSerializer, ns); xmlReader.MoveToContent (); xmlReader.ReadStartElement ("Body", ns); xmlReader.MoveToContent (); if (xmlReader.LocalName == "Fault" && xmlReader.NamespaceURI == ns) bodySerializer = ns == Soap12EnvelopeNamespace ? Soap12Fault.Serializer : Fault.Serializer; body = bodySerializer.Deserialize (xmlReader); }
internal SoapMessage () { headers = new SoapHeaderCollection (); }
public static void ReadSoapMessage (XmlTextReader xmlReader, SoapMethodStubInfo method, SoapHeaderDirection dir, bool soap12, out object body, out SoapHeaderCollection headers) { XmlSerializer bodySerializer = method.GetBodySerializer (dir, false);// no need to worry about soap12 arg since no call for Fault anyways here. XmlSerializer headerSerializer = method.GetHeaderSerializer (dir); ReadSoapMessage (xmlReader, bodySerializer, headerSerializer, soap12, out body, out headers); }
internal void ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNs, string encodingStyle) { reader.MoveToContent(); if (!reader.IsStartElement(Soap.Header, envelopeNs)) { return; } if (reader.IsEmptyElement) { reader.Skip(); return; } this.unknownHeaders = new SoapHeaderCollection(); this.unreferencedHeaders = new SoapHeaderCollection(); // thread hash code is used to differentiate between deserializations in event callbacks this.currentThread = Thread.CurrentThread.GetHashCode(); this.envelopeNs = envelopeNs; XmlElementEventHandler unknownHandler = new XmlElementEventHandler(this.OnUnknownElement); UnreferencedObjectEventHandler unreferencedHandler = new UnreferencedObjectEventHandler(this.OnUnreferencedObject); serializer.UnknownElement += unknownHandler; serializer.UnreferencedObject += unreferencedHandler; reader.ReadStartElement(); reader.MoveToContent(); // SOAP12: not using encodingStyle //object[] headerValues = (object[])serializer.Deserialize(reader, encodingStyle); object[] headerValues = (object[])serializer.Deserialize(reader); for (int i = 0; i < headerValues.Length; i++) { if (headerValues[i] != null) { SoapHeader header = (SoapHeader)headerValues[i]; header.DidUnderstand = true; headers.Add(header); } } serializer.UnknownElement -= unknownHandler; serializer.UnreferencedObject -= unreferencedHandler; this.currentThread = 0; this.envelopeNs = null; foreach (SoapHeader header in this.unreferencedHeaders) { headers.Add(header); } this.unreferencedHeaders = null; foreach (SoapHeader header in this.unknownHeaders) { headers.Add(header); } this.unknownHeaders = null; while (reader.NodeType == XmlNodeType.Whitespace) { reader.Skip(); } if (reader.NodeType == XmlNodeType.None) { reader.Skip(); } else { reader.ReadEndElement(); } }
public static void WriteSoapMessage (XmlTextWriter xtw, SoapMethodStubInfo method, SoapHeaderDirection dir, object bodyContent, SoapHeaderCollection headers, bool soap12) { SoapBindingUse methodUse = dir == SoapHeaderDirection.Fault ? SoapBindingUse.Literal : method.Use; XmlSerializer bodySerializer = method.GetBodySerializer (dir, soap12); XmlSerializer headerSerializer = method.GetHeaderSerializer (dir); object[] headerArray = method.GetHeaderValueArray (dir, headers); WriteSoapMessage (xtw, methodUse, bodySerializer, headerSerializer, bodyContent, headerArray, soap12); }
public static void WriteHeaders(XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNS, bool serviceDefaultIsEncoded, string envelopeNS) { if (headers.Count != 0) { SoapProtocolVersion version; string str; writer.WriteStartElement("Header", envelopeNS); if (envelopeNS == "http://www.w3.org/2003/05/soap-envelope") { version = SoapProtocolVersion.Soap12; str = "http://www.w3.org/2003/05/soap-encoding"; } else { version = SoapProtocolVersion.Soap11; str = "http://schemas.xmlsoap.org/soap/encoding/"; } int num = 0; ArrayList list = new ArrayList(); SoapHeader[] o = new SoapHeader[mappings.Length]; bool[] flagArray = new bool[o.Length]; for (int i = 0; i < headers.Count; i++) { SoapHeader header = headers[i]; if (header != null) { header.version = version; if (header is SoapUnknownHeader) { list.Add(header); num++; } else { int num3; if (((num3 = FindMapping(mappings, header, direction)) >= 0) && !flagArray[num3]) { o[num3] = header; flagArray[num3] = true; } else { list.Add(header); } } } } int num4 = list.Count - num; if (isEncoded && (num4 > 0)) { SoapHeader[] array = new SoapHeader[mappings.Length + num4]; o.CopyTo(array, 0); int length = mappings.Length; for (int k = 0; k < list.Count; k++) { if (!(list[k] is SoapUnknownHeader)) { array[length++] = (SoapHeader)list[k]; } } o = array; } TraceMethod caller = Tracing.On ? new TraceMethod(typeof(SoapHeaderHandling), "WriteHeaders", new object[0]) : null; if (Tracing.On) { object[] args = new object[5]; args[0] = writer; args[1] = o; args[3] = isEncoded ? str : null; args[4] = "h_"; Tracing.Enter(Tracing.TraceId("TraceWriteHeaders"), caller, new TraceMethod(serializer, "Serialize", args)); } serializer.Serialize(writer, o, null, isEncoded ? str : null, "h_"); if (Tracing.On) { Tracing.Exit(Tracing.TraceId("TraceWriteHeaders"), caller); } foreach (SoapHeader header2 in list) { if (header2 is SoapUnknownHeader) { SoapUnknownHeader header3 = (SoapUnknownHeader)header2; if (header3.Element != null) { header3.Element.WriteTo(writer); } } else if (!isEncoded) { string literalNamespace = SoapReflector.GetLiteralNamespace(defaultNS, serviceDefaultIsEncoded); XmlSerializer target = new XmlSerializer(header2.GetType(), literalNamespace); if (Tracing.On) { Tracing.Enter(Tracing.TraceId("TraceWriteHeaders"), caller, new TraceMethod(target, "Serialize", new object[] { writer, header2 })); } target.Serialize(writer, header2); if (Tracing.On) { Tracing.Exit(Tracing.TraceId("TraceWriteHeaders"), caller); } } } for (int j = 0; j < headers.Count; j++) { SoapHeader header4 = headers[j]; if (header4 != null) { header4.version = SoapProtocolVersion.Default; } } writer.WriteEndElement(); writer.Flush(); } }
public static void SetHeaderMembers(SoapHeaderCollection headers, object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool client) { bool[] headerHandled = new bool[headers.Count]; if (mappings != null) { for (int i = 0; i < mappings.Length; i++) { SoapHeaderMapping mapping = mappings[i]; if ((mapping.direction & direction) == 0) continue; if (mapping.repeats) { ArrayList list = new ArrayList(); for (int j = 0; j < headers.Count; j++) { SoapHeader header = headers[j]; if (headerHandled[j]) continue; if (mapping.headerType.IsAssignableFrom(header.GetType())) { list.Add(header); headerHandled[j] = true; } } MemberHelper.SetValue(mapping.memberInfo, target, list.ToArray(mapping.headerType)); } else { bool handled = false; for (int j = 0; j < headers.Count; j++) { SoapHeader header = headers[j]; if (headerHandled[j]) continue; if (mapping.headerType.IsAssignableFrom(header.GetType())) { if (handled) { header.DidUnderstand = false; continue; } handled = true; MemberHelper.SetValue(mapping.memberInfo, target, header); headerHandled[j] = true; } } } } } for (int i = 0; i < headerHandled.Length; i++) { if (!headerHandled[i]) { SoapHeader header = headers[i]; if (header.MustUnderstand && !header.DidUnderstand) { throw new SoapHeaderException(Res.GetString(Res.WebCannotUnderstandHeader, GetHeaderElementName(header)), new XmlQualifiedName(Soap.Code.MustUnderstand, Soap.Namespace)); } } } }
// return first missing header name; public string ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNS, string encodingStyle, bool checkRequiredHeaders) { string missingHeader = null; reader.MoveToContent(); if (!reader.IsStartElement(Soap.Element.Header, envelopeNS)) { if (checkRequiredHeaders && mappings != null && mappings.Length > 0) { missingHeader = GetHeaderElementName(mappings[0].headerType); } return(missingHeader); } if (reader.IsEmptyElement) { reader.Skip(); return(missingHeader); } this.unknownHeaders = new SoapHeaderCollection(); this.unreferencedHeaders = new SoapHeaderCollection(); // thread hash code is used to differentiate between deserializations in event callbacks this.currentThread = Thread.CurrentThread.GetHashCode(); this.envelopeNS = envelopeNS; int depth = reader.Depth; reader.ReadStartElement(); reader.MoveToContent(); XmlDeserializationEvents events = new XmlDeserializationEvents(); events.OnUnknownElement = new XmlElementEventHandler(this.OnUnknownElement); events.OnUnreferencedObject = new UnreferencedObjectEventHandler(this.OnUnreferencedObject); TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadHeaders") : null; if (Tracing.On) { Tracing.Enter(Tracing.TraceId(Res.TraceReadHeaders), caller, new TraceMethod(serializer, "Deserialize", reader, encodingStyle)); } object[] headerValues = (object[])serializer.Deserialize(reader, encodingStyle, events); if (Tracing.On) { Tracing.Exit(Tracing.TraceId(Res.TraceReadHeaders), caller); } for (int i = 0; i < headerValues.Length; i++) { if (headerValues[i] != null) { SoapHeader header = (SoapHeader)headerValues[i]; header.DidUnderstand = true; headers.Add(header); } else if (checkRequiredHeaders) { // run time check for R2738 A MESSAGE MUST include all soapbind:headers specified on a wsdl:input or wsdl:output of a wsdl:operationwsdl:binding that describes it. if (missingHeader == null) { missingHeader = GetHeaderElementName(mappings[i].headerType); } } } this.currentThread = 0; this.envelopeNS = null; foreach (SoapHeader header in this.unreferencedHeaders) { headers.Add(header); } this.unreferencedHeaders = null; foreach (SoapHeader header in this.unknownHeaders) { headers.Add(header); } this.unknownHeaders = null; // 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(); } return(missingHeader); }
public static void EnsureHeadersUnderstood(SoapHeaderCollection headers) { throw new NotImplementedException(); }
public string ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNS, string encodingStyle, bool checkRequiredHeaders) { string headerElementName = null; reader.MoveToContent(); if (!reader.IsStartElement("Header", envelopeNS)) { if ((checkRequiredHeaders && (mappings != null)) && (mappings.Length > 0)) { headerElementName = GetHeaderElementName(mappings[0].headerType); } return headerElementName; } if (reader.IsEmptyElement) { reader.Skip(); return headerElementName; } this.unknownHeaders = new SoapHeaderCollection(); this.unreferencedHeaders = new SoapHeaderCollection(); this.currentThread = Thread.CurrentThread.GetHashCode(); this.envelopeNS = envelopeNS; int depth = reader.Depth; reader.ReadStartElement(); reader.MoveToContent(); XmlDeserializationEvents events = new XmlDeserializationEvents { OnUnknownElement = new XmlElementEventHandler(this.OnUnknownElement), OnUnreferencedObject = new UnreferencedObjectEventHandler(this.OnUnreferencedObject) }; TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadHeaders", new object[0]) : null; if (Tracing.On) { Tracing.Enter(Tracing.TraceId("TraceReadHeaders"), caller, new TraceMethod(serializer, "Deserialize", new object[] { reader, encodingStyle })); } object[] objArray = (object[]) serializer.Deserialize(reader, encodingStyle, events); if (Tracing.On) { Tracing.Exit(Tracing.TraceId("TraceReadHeaders"), caller); } for (int i = 0; i < objArray.Length; i++) { if (objArray[i] != null) { SoapHeader header = (SoapHeader) objArray[i]; header.DidUnderstand = true; headers.Add(header); } else if (checkRequiredHeaders && (headerElementName == null)) { headerElementName = GetHeaderElementName(mappings[i].headerType); } } this.currentThread = 0; this.envelopeNS = null; foreach (SoapHeader header2 in this.unreferencedHeaders) { headers.Add(header2); } this.unreferencedHeaders = null; foreach (SoapHeader header3 in this.unknownHeaders) { headers.Add(header3); } this.unknownHeaders = null; while ((depth < reader.Depth) && reader.Read()) { } if (reader.NodeType == XmlNodeType.EndElement) { reader.Read(); } return headerElementName; }
public static void WriteHeaders(XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNS, bool serviceDefaultIsEncoded, string envelopeNS) { if (headers.Count == 0) { return; } writer.WriteStartElement(Soap.Element.Header, envelopeNS); SoapProtocolVersion version; string encodingStyle; if (envelopeNS == Soap12.Namespace) { version = SoapProtocolVersion.Soap12; encodingStyle = Soap12.Encoding; } else { version = SoapProtocolVersion.Soap11; encodingStyle = Soap.Encoding; } int unknownHeaderCount = 0; ArrayList otherHeaders = new ArrayList(); SoapHeader[] headerArray = new SoapHeader[mappings.Length]; bool[] headerSet = new bool[headerArray.Length]; for (int i = 0; i < headers.Count; i++) { SoapHeader header = headers[i]; if (header == null) { continue; } int headerPosition; header.version = version; if (header is SoapUnknownHeader) { otherHeaders.Add(header); unknownHeaderCount++; } else if ((headerPosition = FindMapping(mappings, header, direction)) >= 0 && !headerSet[headerPosition]) { headerArray[headerPosition] = header; headerSet[headerPosition] = true; } else { otherHeaders.Add(header); } } int otherHeaderCount = otherHeaders.Count - unknownHeaderCount; if (isEncoded && otherHeaderCount > 0) { SoapHeader[] newHeaderArray = new SoapHeader[mappings.Length + otherHeaderCount]; headerArray.CopyTo(newHeaderArray, 0); // fill in the non-statically known headers (otherHeaders) starting after the statically-known ones int count = mappings.Length; for (int i = 0; i < otherHeaders.Count; i++) { if (!(otherHeaders[i] is SoapUnknownHeader)) { newHeaderArray[count++] = (SoapHeader)otherHeaders[i]; } } headerArray = newHeaderArray; } TraceMethod caller = Tracing.On ? new TraceMethod(typeof(SoapHeaderHandling), "WriteHeaders") : null; if (Tracing.On) { Tracing.Enter(Tracing.TraceId(Res.TraceWriteHeaders), caller, new TraceMethod(serializer, "Serialize", writer, headerArray, null, isEncoded ? encodingStyle : null, "h_")); } serializer.Serialize(writer, headerArray, null, isEncoded ? encodingStyle : null, "h_"); if (Tracing.On) { Tracing.Exit(Tracing.TraceId(Res.TraceWriteHeaders), caller); } foreach (SoapHeader header in otherHeaders) { if (header is SoapUnknownHeader) { SoapUnknownHeader unknown = (SoapUnknownHeader)header; if (unknown.Element != null) { unknown.Element.WriteTo(writer); } } else if (!isEncoded) // encoded headers already appended to members mapping { string ns = SoapReflector.GetLiteralNamespace(defaultNS, serviceDefaultIsEncoded); XmlSerializer headerSerializer = new XmlSerializer(header.GetType(), ns); if (Tracing.On) { Tracing.Enter(Tracing.TraceId(Res.TraceWriteHeaders), caller, new TraceMethod(headerSerializer, "Serialize", writer, header)); } headerSerializer.Serialize(writer, header); if (Tracing.On) { Tracing.Exit(Tracing.TraceId(Res.TraceWriteHeaders), caller); } } } // reset the soap version for (int i = 0; i < headers.Count; i++) { SoapHeader header = headers[i]; if (header != null) { header.version = SoapProtocolVersion.Default; } } writer.WriteEndElement(); writer.Flush(); }
// return first missing header name; public string ReadHeaders(XmlReader reader, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, string envelopeNS, string encodingStyle, bool checkRequiredHeaders) { string missingHeader = null; reader.MoveToContent(); if (!reader.IsStartElement(Soap.Element.Header, envelopeNS)) { if (checkRequiredHeaders && mappings != null && mappings.Length > 0) missingHeader = GetHeaderElementName(mappings[0].headerType); return missingHeader; } if (reader.IsEmptyElement) { reader.Skip(); return missingHeader; } this.unknownHeaders = new SoapHeaderCollection(); this.unreferencedHeaders = new SoapHeaderCollection(); // thread hash code is used to differentiate between deserializations in event callbacks this.currentThread = Thread.CurrentThread.GetHashCode(); this.envelopeNS = envelopeNS; int depth = reader.Depth; reader.ReadStartElement(); reader.MoveToContent(); XmlDeserializationEvents events = new XmlDeserializationEvents(); events.OnUnknownElement = new XmlElementEventHandler(this.OnUnknownElement); events.OnUnreferencedObject = new UnreferencedObjectEventHandler(this.OnUnreferencedObject); TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadHeaders") : null; if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceReadHeaders), caller, new TraceMethod(serializer, "Deserialize", reader, encodingStyle)); object[] headerValues = (object[])serializer.Deserialize(reader, encodingStyle, events); if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceReadHeaders), caller); for (int i = 0; i < headerValues.Length; i++) { if (headerValues[i] != null) { SoapHeader header = (SoapHeader)headerValues[i]; header.DidUnderstand = true; headers.Add(header); } else if (checkRequiredHeaders) { // run time check for R2738 A MESSAGE MUST include all soapbind:headers specified on a wsdl:input or wsdl:output of a wsdl:operationwsdl:binding that describes it. if (missingHeader == null) missingHeader = GetHeaderElementName(mappings[i].headerType); } } this.currentThread = 0; this.envelopeNS = null; foreach (SoapHeader header in this.unreferencedHeaders) { headers.Add(header); } this.unreferencedHeaders = null; foreach (SoapHeader header in this.unknownHeaders) { headers.Add(header); } this.unknownHeaders = null; // 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(); } return missingHeader; }
public static void WriteHeaders(XmlWriter writer, XmlSerializer serializer, SoapHeaderCollection headers, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, bool isEncoded, string defaultNS, bool serviceDefaultIsEncoded, string envelopeNS) { if (headers.Count == 0) return; writer.WriteStartElement(Soap.Element.Header, envelopeNS); SoapProtocolVersion version; string encodingStyle; if (envelopeNS == Soap12.Namespace) { version = SoapProtocolVersion.Soap12; encodingStyle = Soap12.Encoding; } else { version = SoapProtocolVersion.Soap11; encodingStyle = Soap.Encoding; } int unknownHeaderCount = 0; ArrayList otherHeaders = new ArrayList(); SoapHeader[] headerArray = new SoapHeader[mappings.Length]; bool[] headerSet = new bool[headerArray.Length]; for (int i = 0; i < headers.Count; i++) { SoapHeader header = headers[i]; if (header == null) continue; int headerPosition; header.version = version; if (header is SoapUnknownHeader) { otherHeaders.Add(header); unknownHeaderCount++; } else if ((headerPosition = FindMapping(mappings, header, direction)) >= 0 && !headerSet[headerPosition]) { headerArray[headerPosition] = header; headerSet[headerPosition] = true; } else { otherHeaders.Add(header); } } int otherHeaderCount = otherHeaders.Count - unknownHeaderCount; if (isEncoded && otherHeaderCount > 0) { SoapHeader[] newHeaderArray = new SoapHeader[mappings.Length + otherHeaderCount]; headerArray.CopyTo(newHeaderArray, 0); // fill in the non-statically known headers (otherHeaders) starting after the statically-known ones int count = mappings.Length; for (int i = 0; i < otherHeaders.Count; i++) { if (!(otherHeaders[i] is SoapUnknownHeader)) newHeaderArray[count++] = (SoapHeader)otherHeaders[i]; } headerArray = newHeaderArray; } TraceMethod caller = Tracing.On ? new TraceMethod(typeof(SoapHeaderHandling), "WriteHeaders") : null; if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceWriteHeaders), caller, new TraceMethod(serializer, "Serialize", writer, headerArray, null, isEncoded ? encodingStyle : null, "h_")); serializer.Serialize(writer, headerArray, null, isEncoded ? encodingStyle : null, "h_"); if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceWriteHeaders), caller); foreach (SoapHeader header in otherHeaders) { if (header is SoapUnknownHeader) { SoapUnknownHeader unknown = (SoapUnknownHeader)header; if (unknown.Element != null) unknown.Element.WriteTo(writer); } else if (!isEncoded) { // encoded headers already appended to members mapping string ns = SoapReflector.GetLiteralNamespace(defaultNS, serviceDefaultIsEncoded); XmlSerializer headerSerializer = new XmlSerializer(header.GetType(), ns); if (Tracing.On) Tracing.Enter(Tracing.TraceId(Res.TraceWriteHeaders), caller, new TraceMethod(headerSerializer, "Serialize", writer, header)); headerSerializer.Serialize(writer, header); if (Tracing.On) Tracing.Exit(Tracing.TraceId(Res.TraceWriteHeaders), caller); } } // reset the soap version for (int i = 0; i < headers.Count; i++) { SoapHeader header = headers[i]; if (header != null) header.version = SoapProtocolVersion.Default; } writer.WriteEndElement(); writer.Flush(); }
public object[] GetHeaderValueArray (SoapHeaderDirection dir, SoapHeaderCollection headers) { HeaderInfo[] headerInfos = GetHeaders (dir); if (headerInfos == null) return null; object[] hs = new object [headerInfos.Length]; for (int n=0; n<headers.Count; n++) { SoapHeader h = headers[n]; Type t = h.GetType(); for (int i=0; i<headerInfos.Length; i++) if (headerInfos [i].HeaderType == t) hs [i] = h; } return hs; }
public static void WriteUnknownHeaders(XmlWriter writer, SoapHeaderCollection headers, string envelopeNS) { bool first = true; foreach (SoapHeader header in headers) { SoapUnknownHeader unknown = header as SoapUnknownHeader; if (unknown != null) { if (first) { writer.WriteStartElement(Soap.Element.Header, envelopeNS); first = false; } if (unknown.Element != null) unknown.Element.WriteTo(writer); } } if (!first) writer.WriteEndElement(); // </soap:Header> }