• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Soap.SoapFormatter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



SoapFormatter类属于System.Runtime.Serialization.Formatters.Soap命名空间,在下文中一共展示了SoapFormatter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Save

        public static bool Save(Type static_class, string filename)
        {
            try
            {
                FieldInfo[] fields = static_class.GetFields(BindingFlags.Static | BindingFlags.NonPublic);

                object[,] a = new object[fields.Length, 2];
                int i = 0;
                foreach (FieldInfo field in fields)
                {
                    a[i, 0] = field.Name;
                    a[i, 1] = field.GetValue(null);
                    i++;
                };
                Stream f = File.Open(filename, FileMode.Create);
                SoapFormatter formatter = new SoapFormatter();
                formatter.Serialize(f, a);
                f.Close();
                return true;
            }
            catch
            {
                return false;
            }
        }
开发者ID:megadrow,项目名称:Study,代码行数:25,代码来源:SerializeStatic.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: 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


示例4: logger

 public logger()
 {
     //bugs = new List<bugData>();
     //x = new XmlSerializer(bugs.GetType());
     sf = new SoapFormatter();
     initialize();
 }
开发者ID:nitinyadav,项目名称:SmartBuilder,代码行数:7,代码来源:logger.cs


示例5: 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


示例6: 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


示例7: PersisUser

        static void PersisUser()
        {
            List<JamesBondCar> myCars = new List<JamesBondCar>();

            XmlSerializer xmlSer = new XmlSerializer(typeof(Person));
            Person ps = new Person();
            using (Stream fStream = new FileStream("Person.xml", FileMode.Create, FileAccess.Write, FileShare.None))
            {
                xmlSer.Serialize(fStream, ps);
            }

            SoapFormatter soapFormat = new SoapFormatter();
            using (Stream fStream = new FileStream("Person.soap", FileMode.Create, FileAccess.Write, FileShare.None))
            {
                soapFormat.Serialize(fStream, ps);
            }

            BinaryFormatter binFormat = new BinaryFormatter();
            UserPrefs userData = new UserPrefs();
            userData.WindowColor = "Yelllow";
            userData.FontSize = 50;
            //Store object in a local file
            using (Stream fStream = new FileStream("user.dat", FileMode.Create, FileAccess.Write, FileShare.None))
            {
                binFormat.Serialize(fStream, userData);
            }
        }
开发者ID:ZLLselfRedeem,项目名称:zllinmitu,代码行数:27,代码来源:Program.cs


示例8: 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


示例9: ReadFromConfigureFile

        /// <summary>
        /// 读取配置文件到当前类
        /// </summary>
        public void ReadFromConfigureFile()
        {
            //从配置文件中读
            Log.OverallLog.Log("读取配置文件");
            IFormatter formatter = new SoapFormatter();
            //当前dll的目录下的config.cfg
            string pathOfConfigFile = GetConfigPath();
            System.IO.Stream stream=null;
            try
            {
                 stream = new System.IO.FileStream(pathOfConfigFile, FileMode.Open,
                        FileAccess.Read, FileShare.Read);
                ApplicationSettings obj = (ApplicationSettings)formatter.Deserialize(stream);

                this.FlushTime = obj.FlushTime;
                this.ItemConfigWoods = obj.ItemConfigWoods;
                this.SwitchTypeItems = obj.SwitchTypeItems;

                stream.Close();
            }
            catch (FileNotFoundException)
            {

                Log.OverallLog.LogForErr("配置文件不存在");
                return;
            }
            catch (SerializationException)
            {
                if (stream != null)
                    stream.Dispose();
                System.IO.File.Delete(pathOfConfigFile);
                Log.OverallLog.LogForErr("配置文件存在错误,试图删除");
            }
        }
开发者ID:slayercat,项目名称:TelnetToGetDisable,代码行数:37,代码来源:ApplicationSettings.cs


示例10: 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


示例11: Main

        static void Main(string[] args)
        {
            ArrayList hobbies = new ArrayList();

            hobbies.Add("Skiing");
            hobbies.Add("Biking");
            hobbies.Add("Snowboarding");

            Person person = new Person("Brian Pfeil", 28, hobbies);

            // Binary formatter
            IFormatter formatter = new BinaryFormatter();
            formatter.Serialize(Console.OpenStandardOutput(), person);
            Console.WriteLine("End Binary Formatter output.  Press enter to continue ...");
            Console.Read();

            // SOAP formatter
            formatter = new SoapFormatter();
            formatter.Serialize(Console.OpenStandardOutput(), person);
            Console.WriteLine("End Soap Formatter output.  Press enter to continue ...");
            Console.Read();

            //XmlSerializer xmlSerializer = new XmlSerializer(typeof(Person));
            //xmlSerializer.Serialize(Console.Out, person);

            Console.Read();
        }
开发者ID:venkatarajasekhar,项目名称:repo,代码行数:27,代码来源:Class1.cs


示例12: BinarySerialize

        public void BinarySerialize(Type ReturnType, object obj)
        {
            var formatter = new SoapFormatter();

            using (Stream s = File.Create(ConfigFile + ".dat"))
                formatter.Serialize(s, obj);
        }
开发者ID:PCurd,项目名称:MyFitnessPalApp,代码行数:7,代码来源:LoadConfig.cs


示例13: 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


示例14: WriteXml

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

            try
            {
                var fields = static_class.GetFields(BindingFlags.Static | BindingFlags.Public);

                object[,] a = new object[fields.Length, 2];
                var i = 0;
                foreach (var field in fields)
                {
                    a[i, 0] = field.Name;
                    a[i, 1] = field.GetValue(null);
                    i++;
                }
                Stream f = File.Open(filename, FileMode.Create);
                SoapFormatter formatter = new SoapFormatter();
                formatter.Serialize(f, a);
                f.Close();
            }
            catch
            {
            }
        }
开发者ID:psionika,项目名称:MikrotikSSHBackup,代码行数:26,代码来源:Class_Settings.cs


示例15: SavePrinters

 protected void SavePrinters( Printer[] printers )
 {
     FileStream f = new FileStream(configFileName, FileMode.Create);
     SoapFormatter formatter = new SoapFormatter();
     formatter.Serialize(f, printers);
     f.Close();
 }
开发者ID:esanbock,项目名称:inkleveler,代码行数:7,代码来源:InkPopup.cs


示例16: 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


示例17: 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


示例18: Main

        static void Main(string[] args)
        {
            Employee empl = new Employee("Müller", 28, 1, 10000, "ssn-0001");

              // Save it with a BinaryFormatter
              FileInfo f = new FileInfo(@"L7U2_EmployeeBin.txt");
              using (BinaryWriter bw = new BinaryWriter(f.OpenWrite()))
              {
            bw.Write(empl.Age);
            bw.Write(empl.ID);
            bw.Write(empl.Name);
            bw.Write(empl.Pay);
            bw.Write(empl.SocialSecurityNumber);
              }

              // Save it with a SoapFormatter
              using (FileStream str = File.Create("L7U2_EmployeeSoap.txt"))
              {
            SoapFormatter sf = new SoapFormatter();
            sf.Serialize(str, empl);
              }

              // Save it with a XmlSerializer
              XmlSerializer SerializerObj = new XmlSerializer(typeof(Employee));

              TextWriter WriteFileStream = new StreamWriter(@"L7U2_EmployeeXml.txt");
              SerializerObj.Serialize(WriteFileStream, empl);

              WriteFileStream.Close();
        }
开发者ID:babelfish42,项目名称:dotNet,代码行数:30,代码来源:Program.cs


示例19: Load

        public static bool Load(Type staticClass, string filename, bool binaryFormatter = true)
        {
            try
            {
                FieldInfo[] fields = staticClass.GetFields(BindingFlags.Static | BindingFlags.Public);
                object[,] a;
                Stream f = File.Open(filename, FileMode.Open);

                IFormatter formatter;

                if (binaryFormatter)
                    formatter = new BinaryFormatter();
                else
                    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))
                    {
                        field.SetValue(null, a[i, 1]);
                    }
                    i++;
                };
                return true;
            }
            catch
            {
                return false;
            }
        }
开发者ID:Noxalus,项目名称:Danmaku-no-Kyojin,代码行数:34,代码来源:StaticClassSerializer.cs


示例20: Main

		static void Main (string[] args)
		{
			object x = null;
			string strTypes = null;
			string argValues = null;
			
			if (args.Length == 1) {
				Type t = Type.GetType (args[0]);
				Console.WriteLine ("\nPlease enter the arguments to the constructor for type {0}", t.ToString());
				strTypes = Console.ReadLine ();
				Console.WriteLine ("\nPlease enter the values");
				argValues = Console.ReadLine ();
				Type[] types = ToTypeArray (strTypes.Split (','));
				string[] param = argValues.Split (',');
				
				x = LiveCreateObject (t, types, param);
			} else {
				x = StaticCreateObject ();
			}
			
			string fileName = x.GetType().FullName + ".xml";
			Stream output = new FileStream (fileName, FileMode.Create,
							FileAccess.Write, FileShare.None);
			IFormatter formatter = new SoapFormatter ();
			
			formatter.Serialize ((Stream) output, x);
			output.Close ();
		}
开发者ID:nobled,项目名称:mono,代码行数:28,代码来源:serialize.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Json.DataContractJsonSerializer类代码示例发布时间:2022-05-26
下一篇:
C# Binary.__BinaryParser类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap