Example #1
0
        private Client ReadClientFromFile()
        {
            var encoder = new BasicHttpBinding(BasicHttpSecurityMode.None).CreateBindingElements()
                          .Find <MessageEncodingBindingElement>()?.CreateMessageEncoderFactory()
                          .Encoder;

            const string resourceName = "WebSvc1.Resources.client.xml";
            var          serialiser   = new XmlSerializer(typeof(Client));

            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
            {
                Message requestMessage = encoder.ReadMessage(stream, 0x10000, "text/xml");

                using (var xmlReader = requestMessage.GetReaderAtBodyContents())
                {
                    xmlReader.ReadStartElement("Process", "http://IntelliFlo.com/");
                    xmlReader.MoveToStartElement("request", "http://IntelliFlo.com/");
                    while (xmlReader.Read())
                    {
                        switch (xmlReader.NodeType)
                        {
                        case XmlNodeType.Element:
                        {
                            if (xmlReader.Name == "personal_client")
                            {
                                var client = serialiser.Deserialize(xmlReader) as Client;
                                return(client);
                            }
                            break;
                        }

                        default:
                            break;
                        }
                    }
                }
            }

            return(null);
        }