本文整理汇总了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();
}
示例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: 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();
}
示例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;
}
示例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);
}
}
示例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;
}
示例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());
}
}
示例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");
}
}
}
示例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();
}
示例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;
}
示例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
{
}
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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;
}