/// <summary> /// Send an Http request containing an mtom message to an endpoint and waits for a response. /// </summary> /// <param name="bodyParts">A reference to the WsMtomBodyParts collection used to generate a mime multipart message.</param> /// <param name="endpointAddress">A string containing the endpoint address of a service that will receive /// <param name="isOneway">True = don't wait for response, false means wait for a response.</param> /// <param name="isChuncked">If true true the message will be chunk encoded.</param> /// <returns> /// A DpwSoapResponse object containing a WsWsaHeader and an XmlReader or null if no response is received /// or parsing fails. /// </returns> public DpwsSoapResponse SendRequest(ref WsMtomBodyParts bodyParts, string endpointAddress, bool isOneWay, bool isChuncked) { WsMtomParams mtomParams = new WsMtomParams(); if (bodyParts.Boundary == null) bodyParts.Boundary = Guid.NewGuid().ToString() + '-' + Guid.NewGuid().ToString().Substring(0, 33); mtomParams.start = bodyParts.Start; mtomParams.boundary = bodyParts.Boundary; WsMtom mtom = new WsMtom(); byte[] message = mtom.CreateMessage(bodyParts); WsMessage response = SendRequest(message, endpointAddress, isOneWay, isChuncked, mtomParams); if (isOneWay) return null; XmlReader reader; WsWsaHeader header; try { reader = WsSoapMessageParser.ParseSoapMessage(response.Message, out header); bodyParts = response.BodyParts; } catch { System.Ext.Console.Write("ParseSoapMessage failed."); return null; } return new DpwsSoapResponse(header, reader); }
/// <summary> /// Create an mtom message from body parts list /// </summary> /// <param name="bodyParts">Body Parts collection used to create the Mtom message</param> /// <returns>byte array containing an mtom message</returns> public byte[] CreateMessage(WsMtomBodyParts bodyParts) { if (bodyParts == null) { throw new ArgumentNullException(); // "Mtom body parts collection must not be null."); } if (bodyParts.Count == 0) { throw new ArgumentException(); // "Mtom bodyParts must at least contain a soap message body part."); } // Initialize the internal buffer, position and length m_buffer = new byte[m_growSize]; m_curPos = 0; m_length = 0; // If mtom body parts boundary is null generate one if (bodyParts.Boundary == null) { m_bodyParts.Boundary = Guid.NewGuid().ToString() + '-' + Guid.NewGuid().ToString().Substring(0, 33); } else { m_bodyParts.Boundary = bodyParts.Boundary; } // If start is null set to the first body part content id. if (bodyParts.Start == null) { m_bodyParts.Start = bodyParts[0].ContentID; } else { m_bodyParts.Start = bodyParts.Start; } WriteLine("--" + bodyParts.Boundary); for (int i = 0; i < bodyParts.Count; ++i) { WriteLine(HttpKnownHeaderNames.ContentType + ": " + bodyParts[i].ContentType); WriteLine(HttpKnownHeaderNames.ContentTransferEncoding + ": " + bodyParts[i].ContentTransferEncoding); WriteLine(HttpKnownHeaderNames.ContentID + ": " + bodyParts[i].ContentID); WriteLine(""); WriteBytes(bodyParts[i].Content.ToArray()); WriteLine(""); if (i == bodyParts.Count - 1) { WriteString("--" + bodyParts.Boundary + "--"); } else { WriteLine("--" + bodyParts.Boundary); } } // Create new buffer at the exact length byte[] tempBuff = new byte[m_length]; Array.Copy(m_buffer, tempBuff, m_length); return(tempBuff); }
/// <summary> /// Creates an instance of a DataContractSerilizer used to serialize and deserialize xml to /// and from a type. /// </summary> /// <param name="rootName">A string containing the name of the root element of a type.</param> /// <param name="rootNamespace">A string containing the namespace of the root element of a type.</param> /// <param name="localNamespace">A string containing the namespace of the child element of a type.</param> protected DataContractSerializer(string rootName, string rootNamespace, string localNamespace) { _attributesFound = new ArrayList(); BodyParts = new WsMtomBodyParts(); _rootName = rootName; _rootNamespace = rootNamespace; _localNamespace = localNamespace; _CompressByteArrays = true; }
/// <summary> /// WsMtom - Mtom parser and generator /// </summary> public WsMtom() { m_curPos = 0; m_length = 0; m_buffer = null; m_growSize = 0xFFFF; m_capacity = 0xFFFF; m_maxCapacity = 0xFFFFF; m_utf8Encoding = new UTF8Encoding(); m_bodyParts = new WsMtomBodyParts(); }
/// <summary> /// WsMtom - Mtom parser and generator /// </summary> /// <param name="buffer">byte array containing raw mtom message</param> public WsMtom(byte[] buffer) : this() { if (buffer == null) { throw new NullReferenceException(); // "Mtom buffer must not be null"); } if (buffer.Length > m_maxCapacity) { throw new ArgumentOutOfRangeException(); // "Mtom buffer", "Exceeds max capacity."); } m_buffer = buffer; m_length = buffer.Length; m_bodyParts = new WsMtomBodyParts(); }
/// <summary> /// Create an mtom message from body parts list /// </summary> /// <param name="bodyParts">Body Parts collection used to create the Mtom message</param> /// <returns>byte array containing an mtom message</returns> public byte[] CreateMessage(WsMtomBodyParts bodyParts) { if (bodyParts == null) throw new ArgumentNullException(); // "Mtom body parts collection must not be null."); if (bodyParts.Count == 0) throw new ArgumentException(); // "Mtom bodyParts must at least contain a soap message body part."); // Initialize the internal buffer, position and length m_buffer = new byte[m_growSize]; m_curPos = 0; m_length = 0; // If mtom body parts boundary is null generate one if (bodyParts.Boundary == null) m_bodyParts.Boundary = Guid.NewGuid().ToString() + '-' + Guid.NewGuid().ToString().Substring(0, 33); else m_bodyParts.Boundary = bodyParts.Boundary; // If start is null set to the first body part content id. if (bodyParts.Start == null) m_bodyParts.Start = bodyParts[0].ContentID; else m_bodyParts.Start = bodyParts.Start; WriteLine("--" + bodyParts.Boundary); for (int i = 0; i < bodyParts.Count; ++i) { WriteLine(HttpKnownHeaderNames.ContentType + ": " + bodyParts[i].ContentType); WriteLine(HttpKnownHeaderNames.ContentTransferEncoding + ": " + bodyParts[i].ContentTransferEncoding); WriteLine(HttpKnownHeaderNames.ContentID + ": " + bodyParts[i].ContentID); WriteLine(""); WriteBytes(bodyParts[i].Content.ToArray()); WriteLine(""); if (i == bodyParts.Count - 1) WriteString("--" + bodyParts.Boundary + "--"); else WriteLine("--" + bodyParts.Boundary); } // Create new buffer at the exact length byte[] tempBuff = new byte[m_length]; Array.Copy(m_buffer, tempBuff, m_length); return tempBuff; }
/// <summary> /// WsMtom - Mtom parser and generator /// </summary> /// <param name="buffer">byte array containing raw mtom message</param> public WsMtom(byte[] buffer) : this() { if (buffer == null) throw new NullReferenceException(); // "Mtom buffer must not be null"); if (buffer.Length > m_maxCapacity) throw new ArgumentOutOfRangeException(); // "Mtom buffer", "Exceeds max capacity."); m_buffer = buffer; m_length = buffer.Length; m_bodyParts = new WsMtomBodyParts(); }
/// <summary> /// Gets the content of an WsMtomBodyPart. /// </summary> /// <param name="contentID">A string containing a unique content identifier.</param> /// <param name="bodyParts">A WsMtomBodyParts collection.</param> /// <returns>A byte array containing the body part content.</returns> public byte[] GetBodyPartContent(string contentID, WsMtomBodyParts bodyParts) { WsMtomBodyPart bodyPart = null; if ((bodyPart = bodyParts["<" + contentID.Substring(4) + ">"]) != null) return bodyPart.Content.ToArray(); return null; }
/// <summary> /// Stop tranport services and releases the managed resources used by this class. /// </summary> /// <param name="disposing">True to release managed resources</param> internal void Dispose(bool disposing) { if (disposing) { // Stop the transport services m_httpServiceHost.Stop(); m_udpSeviceHost.Stop(); m_threadLock = null; m_discoClient = null; m_endpointAddress = null; m_eventClient = null; m_mexClient = null; m_eventCallbacks = null; m_transportAddress = null; m_bodyParts = null; m_discoServiceEndpoints = null; m_callbackServiceEndpoints = null; m_udpSeviceHost = null; m_httpServiceHost = null; } }
/// <summary> /// Creates an instance of a WsResponseMessage inintilized from an mtom body parts object. /// </summary> /// <param name="bodyParts">An mtom body parts object.</param> /// <exception cref="ArgumentNullException">If the bodyParts parameter is null.</exception> /// <remarks> /// This contructor processes an mtom body parts collection and uilds an mtom message. /// It also sets the Boundary and StartContenID properties from the body parts object. /// </remarks> public WsMessage(WsMtomBodyParts bodyParts) { Debug.Assert(bodyParts != null); this.MessageType = WsMessageType.Mtom; this.Message = new WsMtom().CreateMessage(bodyParts); this.BodyParts = bodyParts; }
/// <summary> /// WsMtom - Mtom parser and generator /// </summary> public WsMtom() { m_bodyParts = new WsMtomBodyParts(); }
/// <summary> /// Gets the content of an WsMtomBodyPart. /// </summary> /// <param name="contentID">A string containing a unique content identifier.</param> /// <param name="bodyParts">A WsMtomBodyParts collection.</param> /// <returns>A byte array containing the body part content.</returns> public byte[] GetBodyPartContent(string contentID, WsMtomBodyParts bodyParts) { WsMtomBodyPart bodyPart = null; // XmlReader will convert ':' and '/' to their respective HEX values (%3A, %2F) // for attributes values. So we need to switch them back in order for the compare to work // We may want to change the XML parser to handle this in a more generic way int idx = contentID.IndexOf("%"); while(idx != -1) { if(contentID[idx+1] == '3' && contentID[idx+2] == 'A') { contentID = contentID.Substring(0, idx) + ":" + contentID.Substring(idx + 3); } else if(contentID[idx+1] == '2' && contentID[idx+2] == 'F') { contentID = contentID.Substring(0, idx) + "/" + contentID.Substring(idx + 3); } idx = contentID.IndexOf("%", idx); } if ((bodyPart = bodyParts["<" + contentID.Substring(4) + ">"]) != null) return bodyPart.Content.ToArray(); return null; }