C# Read Soap Files


Recommended Posts

ok this is driving me nuts so I am missing something simple

right now I know there are only two bodies in this soap file so I am reading each into a class and string them into a Linked List to be compared later (truly read by a web service)

what I would like is something like this

FileStream fs = new FileStream("DataFile.soap", FileMode.Open);
try
{
SoapFormatter formatter = new SoapFormatter();

// Deserialize the class from the file and
// assign the reference to the local variable.
//NOTE this is the part I don't kow how to do
while (!to_END_OF_FILE)
{
plt = (Platforms) formatter.Deserialize(fs);
pList.Add(plt);
}

}
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 (Platforms pl in pList)
{
Console.WriteLine("Platform ID = {0}: using Icon {1}:", pl.PlatformID, pl.Icon);
Console.WriteLine("Position = X {0} Y {1} Z {2} ", pl.LPoint.X, pl.LPoint.Y, pl.LPoint.Z );
Console.WriteLine("Time = {0}", pl.Time);
}
}

its the while loop I don't know how to do,

any help would be great.. I have searched but maybe I am too frustrated to see the answer and need new eyes

Link to post
Share on other sites

ok I had to change the List to an array because you can not serilize a generic.

here is what I did to fix my problem

/*
* Created by SharpDevelop.
* User: huskeyw
* Date: 12/11/2006
* Time: 10:32 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Collections;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Soap;
namespace soapTest
{
class MainClass
{

static List<Platforms> platformList = new List<Platforms>();

[STAThread]
static void Main()
{
Serialize();
Deserialize();
Console.ReadLine();
}

static void Serialize()
{
// Create a Platform .
Point location = new Point(47.623298645,-122.357002258,34.99898);
Point location1 = new Point(47.623298635,-123.357002258,34.99898);
DateTime currentTime = DateTime.Now;
Platforms platform1 = new Platforms(location,"123567","C-130",currentTime.TimeOfDay );
Platforms platform2 = new Platforms(location1,"123569","C-130",currentTime.TimeOfDay );
platformList.Add(platform1);
platformList.Add(platform2);

FileStream filestream = new FileStream("DataFile.soap", FileMode.Create);

// Construct a SoapFormatter and use it
// to serialize the data to the stream.
SoapFormatter formatter = new SoapFormatter();
try
{

formatter.Serialize(filestream, platformList.ToArray());

}
catch (SerializationException e)
{
Console.WriteLine("Failed to serialize. Reason: " + e.Message);
throw;
}
finally
{
filestream.Close();
}
}


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



// 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 class from the file and
// assign the reference to the local variable.


pList.AddRange( (Platforms[]) 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 (Platforms pl in pList)
{
Console.WriteLine("Platform ID = {0}: using Icon {1}:", pl.PlatformID, pl.Icon);
Console.WriteLine("Position = X {0} Y {1} Z {2} ", pl.LPoint.X, pl.LPoint.Y, pl.LPoint.Z );
Console.WriteLine("Time = {0}", pl.Time);
}
}
}
}

Link to post
Share on other sites

Yes, and now it works in mono.. a big step for me...

Link to post
Share on other sites
Yes, and now it works in mono.. a big step for me...

Argh! I was going to try to help yesterday but monodoc didn't give me any hits for SOAP and I didn't want to grope around in the dark. Now I see that monodoc's search feature just sucks.

Edited by jcl
Link to post
Share on other sites

I always tryy for just .NET first then see if I have to change anything for mono. in this case I did not.

My issue for mono is .NET allowed me to create two envelopes in the SOAP file, which is wrong, so I had to manually extract the information. buy by changing to an ArrayList I could serialize it (casting List to an array is the same thing as an arraylist)

so I have not used monodoc, I just have been searching the web.. because the last time I used Monodoc it was missing way too much stuff (I guess that is why Novell has a Job request out to do Mono documentation)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...