本文整理汇总了C#中System.Runtime.Serialization.Formatters.Soap.SoapFormatter类的典型用法代码示例。如果您正苦于以下问题:C# SoapFormatter类的具体用法?C# SoapFormatter怎么用?C# SoapFormatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SoapFormatter类属于System.Runtime.Serialization.Formatters.Soap命名空间,在下文中一共展示了SoapFormatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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;
}
示例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());
}
}
示例4: logger
public logger()
{
//bugs = new List<bugData>();
//x = new XmlSerializer(bugs.GetType());
sf = new SoapFormatter();
initialize();
}
示例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;
}
示例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");
}
}
}
示例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);
}
}
示例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();
}
示例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("配置文件存在错误,试图删除");
}
}
示例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;
}
示例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();
}
示例12: BinarySerialize
public void BinarySerialize(Type ReturnType, object obj)
{
var formatter = new SoapFormatter();
using (Stream s = File.Create(ConfigFile + ".dat"))
formatter.Serialize(s, obj);
}
示例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
{
}
}
示例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
{
}
}
示例15: SavePrinters
protected void SavePrinters( Printer[] printers )
{
FileStream f = new FileStream(configFileName, FileMode.Create);
SoapFormatter formatter = new SoapFormatter();
formatter.Serialize(f, printers);
f.Close();
}