Here is a small sample that relates to your code:
José
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Soap;
namespace ConsoleApplication7
{
[Serializable]
public struct User
{
public string Username;
public string Password;
public string[] Permissions;
}
[Serializable]
public struct Users
{
public User[] RemoteUsers;
}
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
FileStream myStream = File.Create("test.xml");
SoapFormatter myXMLFormat = new SoapFormatter();
User u1;
u1.Password = "abc";
u1.Username = "ABC";
string[] perms = new string[2];
perms[0] = "all";
u1.Permissions = perms;
Users users;
users.RemoteUsers = new User[1];
users.RemoteUsers[0] = u1;
myXMLFormat.Serialize(myStream, users);
myStream.Close();
myStream = File.OpenRead("test.xml");
Users userRead = (Users)myXMLFormat.Deserialize(myStream);
Console.ReadLine();
}
}
}
"Dirk Reske" <_F*******@gmx.net> a écrit dans le message de
news:O0**************@TK2MSFTNGP11.phx.gbl...
I don't know how soap works....I never used it...
can you post some example?
"José Joye" <jose.joye@__No_SPam__bluewin__maPS_oN__.ch> schrieb im
Newsbeitrag news:OQ*************@TK2MSFTNGP12.phx.gbl... BTW, is there any reason why you use XML Serialization instead of SOAP
serialization (using the SOAP formatter)?
I gave a try with the soap one and all is fine
José
"Dirk Reske" <_F*******@gmx.net> a écrit dans le message de
news:O1**************@TK2MSFTNGP12.phx.gbl... No it doesn't work.
But, when I serialize the structure, all works fine.
I get this error only at deserializing....
"José Joye" <jose.joye@__No_SPam__bluewin__maPS_oN__.ch> schrieb im
Newsbeitrag news:Oc**************@TK2MSFTNGP09.phx.gbl...
> Don't you need to put the [Serializable] attribute in front of (at
least) > Users?
>
> José
>
> "Dirk Reske" <_F*******@gmx.net> a écrit dans le message de
> news:eV**************@TK2MSFTNGP09.phx.gbl...
> > Hello,
> >
> > I have following structs
> >
> > public struct User
> > {
> > public string Username;
> > public string Password;
> > public string[] Permissions;
> > }
> >
> > public struct Users
> > {
> > public User[] RemoteUsers;
> > }
> >
> > when I Serialize a Users struct I get following File
> >
> > <?xml version="1.0" encoding="utf-8" ?>
> > <Users xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> > <RemoteUsers>
> > <User>
> > <Username>Admin</Username>
> > <Password>21232F297A57A5A743894A0E4A801FC3</Password>
> > <Permissions>
> > <string>All</string>
> > </Permissions>
> > </User>
> > </RemoteUsers>
> > </Users>
> >
> > all is OK I think..
> >
> > but when I deserialize it using Users users =
> > (Users)serializer.Deserialize(streamReader));
> > I get following error:
> >
> > Error in XML-document (2,2).
> > at
System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader > > xmlReader, String encodingStyle)
> > at
System.Xml.Serialization.XmlSerializer.Deserialize (TextReader > > textReader)
> > at Remote.Users.UserControl.LoadUsers()
> >
> >
>
>