Microsoft.Protocols.TestTools.StackSdk.WsDiscovery.WsDiscoveryService.Deserialize C# (CSharp) Method

Deserialize() private method

Deserialize the wsdiscovery message
private Deserialize ( string data ) : SoapEnvelope
data string The wsdiscovery message data
return Microsoft.Protocols.TestTools.StackSdk.WsDiscovery.SoapMessage.SoapEnvelope
        private SoapEnvelope Deserialize(string data)
        {
            SoapEnvelope result = null;

            XmlAttributes attrs = new XmlAttributes();

            XmlElementAttribute attr = new XmlElementAttribute();
            attr.ElementName = "Body";
            attr.Type = typeof(ProbeOp);
            attrs.XmlElements.Add(attr);

            XmlAttributes attrs2 = new XmlAttributes();
            XmlElementAttribute attr2 = new XmlElementAttribute();
            attr2.ElementName = "Header";
            attr2.Type = typeof(WsdHeader);

            attrs2.XmlElements.Add(attr2);

            XmlAttributeOverrides attros = new XmlAttributeOverrides();
            attros.Add(typeof(SoapEnvelope), "Body", attrs);
            attros.Add(typeof(SoapEnvelope), "Header", attrs2);

            XmlSerializer serializer = new XmlSerializer(typeof(SoapEnvelope), attros);

            try
            {
                XmlTextReader textReader = new XmlTextReader(data);
                textReader.Settings.XmlResolver = null;
                textReader.Settings.DtdProcessing = DtdProcessing.Prohibit;
                result = (SoapEnvelope)serializer.Deserialize(textReader);
            }
            catch (InvalidOperationException e)
            {
                if (null != this.logger)
                {
                    this.logger.AddDebug("An error is encountered while trying to deserialize the received data");
                    this.logger.AddDebug("The received data is " + data);
                }

                throw new InvalidOperationException(@"Failed to deserialize the received data from on-wire.
                      Please check the logs for details. The exception message from .Net framwork is" + e.Message);
            }

            return result;
        }