当前位置: 首页>>代码示例>>C#>>正文


C# SoapFormatter.Deserialize方法代码示例

本文整理汇总了C#中System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize方法的典型用法代码示例。如果您正苦于以下问题:C# SoapFormatter.Deserialize方法的具体用法?C# SoapFormatter.Deserialize怎么用?C# SoapFormatter.Deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Runtime.Serialization.Formatters.Soap.SoapFormatter的用法示例。


在下文中一共展示了SoapFormatter.Deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReceiveDone

 // on a different thread
 private void ReceiveDone(IAsyncResult ar)
 {
     byte[] got;
     try
     {   // at Form.Close time, the last one sometimes fails
         got = listener.EndReceive(ar, ref groupEP);
     }
     catch
     {
         return;
     }
     OnFreqUpdated notify = m_notify;
     if (notify == null)
         return;
     using (MemoryStream stream = new MemoryStream(got))
     {
         SoapFormatter formatter = new SoapFormatter();
         for (;;)
         {
             EntryFrequencyUpdate efu = null;
             try
             {
                 efu = formatter.Deserialize(stream) as EntryFrequencyUpdate;
             }
             catch { }
             if (efu == null)
                 break;
             notify(efu);
         }
     }
     StartListener();
 }
开发者ID:w5xd,项目名称:WlRigRepeater,代码行数:33,代码来源:FreqUpdateUdpListener.cs

示例2: Deserialize

 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public object Deserialize()
 {
     SoapFormatter aSoap = new SoapFormatter();
     FileStream fs = null;
     object obj = null;
     try
     {
         fs = new FileStream(_filename, FileMode.Open);
         obj = aSoap.Deserialize(fs, null);
     }
     catch (FileNotFoundException)
     {
         return null;
     }
     catch (SerializationException)
     {
         return null;
     }
     finally
     {
         if (fs != null)
         {
             fs.Close();
             fs = null;
         }
     }
     return obj;
 }
开发者ID:hkiaipc,项目名称:fnq,代码行数:32,代码来源:SoapSerialize.cs

示例3: Deserialize

        static void Deserialize()
        {
            // Declare the hashtable reference.
            Hashtable addresses = null;

            // Open the file containing the data that you want to deserialize.
            FileStream fs = new FileStream("DataFile.soap", FileMode.Open);
            try
            {
                SoapFormatter formatter = new SoapFormatter();

                // Deserialize the hashtable from the file and
                // assign the reference to the local variable.
                addresses = (Hashtable)formatter.Deserialize(fs);
            }
            catch (SerializationException e)
            {
                Console.WriteLine("Failed to deserialize. Reason: " + e.Message);
                throw;
            }
            finally
            {
                fs.Close();
            }

            // To prove that the table deserialized correctly,
            // display the key/value pairs to the console.
            foreach (DictionaryEntry de in addresses)
            {
                Console.WriteLine("{0} lives at {1}.", de.Key, de.Value);
            }
            Console.ReadKey();
        }
开发者ID:eandbsoftware,项目名称:MCTS_70_536_AllQuestions,代码行数:33,代码来源:Program.cs

示例4: Receive

        public static SocketEntity Receive(NetworkStream ns)
        {
            MemoryStream mem = new MemoryStream();
            SocketEntity entity;
            byte[] data = new byte[4];
            int revc = ns.Read(data, 0, 4);
            int size = BitConverter.ToInt32(data, 0);

            if (size > 0)
            {
                data = new byte[4096];
                revc = ns.Read(data, 0, size);
                mem.Write(data, 0, revc);

                IFormatter formatter = new SoapFormatter();
                mem.Position = 0;
                entity = (SocketEntity)formatter.Deserialize(mem);
                mem.Close();
            }
            else
            {
                entity = null;
            }

            return entity;
        }
开发者ID:qbollen,项目名称:PMSIface,代码行数:26,代码来源:BollenSocket.cs

示例5: WhenConstructorCalledWithSerialization_ExpectPropertiesSetCorrectly

        public void WhenConstructorCalledWithSerialization_ExpectPropertiesSetCorrectly()
        {
            // Arrange
            const int expectedCode = 400;
            const string expectedMessage = "Test Message";

            // Act
            RandomOrgException target = new RandomOrgException(expectedCode, expectedMessage);

            IFormatter formatter = new SoapFormatter();
            MemoryStream stream = new MemoryStream();
            formatter.Serialize(stream, target);
            stream.Position = 0;

            using (var sr = new StreamReader(stream))
            {
                var actualMessage = sr.ReadToEnd();

                // Assert
                actualMessage.Should().Contain(expectedMessage);

                stream.Position = 0;
                RandomOrgException ex = formatter.Deserialize(stream) as RandomOrgException;
                ex.Code.Should().Equal(expectedCode);
                ex.Message.Should().Equal(expectedMessage);
            }

        }
开发者ID:gsteinbacher,项目名称:RandomOrgSharp,代码行数:28,代码来源:RandomOrgExceptionTest.cs

示例6: DeSerialize

        /// <summary>
        /// Deserialisiert die Daten zu einem Object
        /// </summary>
        /// <param name="data"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public static object DeSerialize(this byte[] data, DataFormatType format)
        {
            MemoryStream ms = new MemoryStream(data);
            object objectToSerialize = null;
            try {
                switch (format) {
                    case DataFormatType.Binary:
                        BinaryFormatter bFormatter = new BinaryFormatter();
                        objectToSerialize = bFormatter.Deserialize(ms);
                        break;
                    case DataFormatType.Soap:
                        SoapFormatter sFormatter = new SoapFormatter();
                        objectToSerialize = sFormatter.Deserialize(ms);
                        break;
                    case DataFormatType.XML:
                        throw new NotImplementedException();
                        //XmlSerializer xFormatter = new XmlSerializer();
                        //objectToSerialize = xFormatter.Deserialize(ms);
                        //break;
                }

            #pragma warning disable 0168
            } catch (Exception ex) { }
            #pragma warning restore 0168

            ms.Close();
            return objectToSerialize;
        }
开发者ID:KillerGoldFisch,项目名称:GCharp,代码行数:34,代码来源:ByteArrayExtensions.cs

示例7: ReadXml

        public static void ReadXml()
        {
            try
            {
                var staticClass = typeof(logOnOffSettings);

                if (!File.Exists(Filename)) return;

                var fields = staticClass.GetFields(BindingFlags.Static | BindingFlags.Public);

                using (Stream f = File.Open(Filename, FileMode.Open))
                {
                    var formatter = new SoapFormatter();
                    var a = formatter.Deserialize(f) as object[,];
                    f.Close();
                    if (a != null && a.GetLength(0) != fields.Length) return;
                    var i = 0;
                    foreach (var field in fields)
                    {
                        if (a != null && field.Name == (a[i, 0] as string))
                        {
                            if (a[i, 1] != null)
                                field.SetValue(null, a[i, 1]);
                        }
                        i++;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Trace("ERROR Send to MySQL: {0}", ex.ToString());
            }
        }
开发者ID:psionika,项目名称:logOnOffService,代码行数:33,代码来源:ClassSettings.cs

示例8: WhenConstructorCalledWithSerialization_ExpectPropertiesSetCorrectly

        public void WhenConstructorCalledWithSerialization_ExpectPropertiesSetCorrectly()
        {
            // Act
            RandomOrgRuntimeException target = new RandomOrgRuntimeException();

            IFormatter formatter = new SoapFormatter();
            using (MemoryStream stream = new MemoryStream())
            {
                formatter.Serialize(stream, target);
                stream.Position = 0;

                using (var sr = new StreamReader(stream))
                {
                    var actualMessage = sr.ReadToEnd();

                    // Assert
                    actualMessage.Should().Contain("RandomOrgRuntimeException");

                    stream.Position = 0;
                    RandomOrgRuntimeException ex = formatter.Deserialize(stream) as RandomOrgRuntimeException;
                    ex.Should().Not.Be.Null();
                    ex?.Message.Should().Contain("RandomOrgRuntimeException");
                }
            }
        }
开发者ID:gsteinbacher,项目名称:RandomOrgSharp,代码行数:25,代码来源:RandomOrgRuntimeExceptionTest.cs

示例9: Main

        static void Main(string[] args)
        {
            using (FileStream arquivoEscrita = new FileStream("saida.txt", FileMode.Create, FileAccess.Write))
            {
                Pessoa p = new Pessoa() { Codigo = 1, Nome = "Adão" };

                SoapFormatter sf = new SoapFormatter();

                sf.Serialize(arquivoEscrita, p);

                arquivoEscrita.Close();
            }

            using (FileStream arquivoLeitura = new FileStream("saida.txt", FileMode.Open, FileAccess.Read))
            {
                SoapFormatter sf = new SoapFormatter();

                Pessoa p = sf.Deserialize(arquivoLeitura) as Pessoa;

                arquivoLeitura.Close();

                if(p != null)
                    Console.WriteLine("{0} - {1}", p.Codigo, p.Nome);
            }

            Console.ReadKey();
        }
开发者ID:50minutos,项目名称:VS2010,代码行数:27,代码来源:Program.cs

示例10: Load

 public static Parameters Load(string filename)
 {
     Parameters p = new Parameters();
     PropertyInfo[] properties = typeof(Parameters).GetProperties();
     object[,] a;
     Stream f = File.Open(filename, FileMode.Open);
     SoapFormatter formatter = new SoapFormatter();
     a = formatter.Deserialize(f) as object[,];
     f.Close();
     //if (a.GetLength(0) != properties.Length) return null;
     int i = 0;
     foreach (PropertyInfo property in properties)
     {
         try
         {
             if (property.Name == (a[i, 0] as string))
             {
                 property.SetValue(p, a[i, 1]);
             }
         }
         catch
         {
         }
         i++;
     };
     return p;
 }
开发者ID:hougaard,项目名称:HelpTools,代码行数:27,代码来源:Configuration.cs

示例11: ReadXml

        public static void ReadXml()
        {
            var static_class = typeof(Settings);
            const string filename = "settings.xml";

            try
            {
                var fields = static_class.GetFields(BindingFlags.Static | BindingFlags.Public);
                Stream f = File.Open(filename, FileMode.Open);
                SoapFormatter formatter = new SoapFormatter();
                object[,] a = formatter.Deserialize(f) as object[,];
                f.Close();
                if (a != null && a.GetLength(0) != fields.Length) return;
                var i = 0;
                foreach (var field in fields)
                {
                    if (a != null && field.Name == (a[i, 0] as string))
                    {
                        if (a[i, 1] != null)
                            field.SetValue(null, a[i, 1]);
                    }
                    i++;
                }
            }
            catch
            {
            }
        }
开发者ID:psionika,项目名称:MikrotikSSHBackup,代码行数:28,代码来源:Class_Settings.cs

示例12: Load

 public static bool Load(Type static_class, string filename)
 {
     try
     {
         FieldInfo[] fields = static_class.GetFields(BindingFlags.Static | BindingFlags.NonPublic);
         object[,] a;
         Stream f = File.Open(filename, FileMode.Open);
         SoapFormatter formatter = new SoapFormatter();
         a = formatter.Deserialize(f) as object[,];
         f.Close();
         if (a.GetLength(0) != fields.Length) return false;
         int i = 0;
         foreach (FieldInfo field in fields)
         {
             if (field.Name == (a[i, 0] as string))
             {
                 if (a[i, 1] != null)
                     field.SetValue(null, a[i, 1]);
             }
             i++;
         };
         return true;
     }
     catch
     {
         return false;
     }
 }
开发者ID:megadrow,项目名称:Study,代码行数:28,代码来源:SerializeStatic.cs

示例13: DeSerializeSOAP

 public static object DeSerializeSOAP(MemoryStream memStream){
     object sr = null;
     var deserializer = new SoapFormatter();
     memStream.Position = 0;
     sr = deserializer.Deserialize(memStream);
     memStream.Close();
     return sr;
 }
开发者ID:satr,项目名称:nwebserversample,代码行数:8,代码来源:Serializators.cs

示例14: UnSerialize

 /// <summary>
 /// Désérialise la chaîne en paramètre
 /// </summary>
 /// <param name="value">le dictionnaire de controles</param>
 /// <returns>le dictionnaire de controles désérialisé</returns>
 public ControlDataWrapper[] UnSerialize(string value)
 {
     using (MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(value)))
     {
         IFormatter formatter = new SoapFormatter();
         return (ControlDataWrapper[])formatter.Deserialize(stream);              
     }
 }
开发者ID:NicolasR,项目名称:Composants,代码行数:13,代码来源:SoapSerializer.cs

示例15: DeSerializeSOAP

 public static object DeSerializeSOAP(MemoryStream memStream)
 {
     if (memStream.Position > (long)0 && memStream.CanSeek) memStream.Position = (long)0;
     SoapFormatter soapFormatter = new SoapFormatter();
     object local1 = soapFormatter.Deserialize(memStream);
     memStream.Close();
     return local1;
 }
开发者ID:DefStevo,项目名称:defstevo-collection,代码行数:8,代码来源:Serialize.cs


注:本文中的System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。