persist an array of data

P

Paolo Liverani

I have a webservices that needs to keep internally an array of counters
shared to every session and that should not be cleared even against machine
reboot.
What is the correct/best way to achieve that?
I am storing all of the data in a object and I have tried to serialize it
through xmlserializer but I am getting an zmlserializer error during the
instantation (unable to find a dll with a random name).
Any suggestion would be appreciated.
Paolo Liverani
 
T

Tu-Thach

Store it in a database or a file

Tu-Thac

----- Paolo Liverani wrote: ----

I have a webservices that needs to keep internally an array of counters
shared to every session and that should not be cleared even against machine
reboot
What is the correct/best way to achieve that
I am storing all of the data in a object and I have tried to serialize it
through xmlserializer but I am getting an zmlserializer error during the
instantation (unable to find a dll with a random name)
Any suggestion would be appreciated
Paolo Liverani
 
P

Paolo Liverani

That's what I am doing but :
1) is it the correct/simplest way?
2) why xmlserializer throws an exception?
 
M

[MSFT]

Hi Paolo,

Thank you for using the community.

Regarding the issue, I agree with Tu-Thach that you can save the array of
counters in a database or files. Only in this way, these information won't
get lost after reboot. More detailed, you can load the information from
database in Application_Start of the web service and save them in an
Application variant, so that it can be shared by each session.

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
P

Paolo Liverani

This is the code,

Public Class TestClass

Public arrayOfArrayList(10) As ArrayList

End Class

<WebMethod()> Public Function HelloWorld() As String

Dim test As TestClass = New TestClass

Dim sw As IO.StreamWriter = New
StreamWriter(File.Open("c:\temp\statoWebService.xml",
System.IO.FileMode.OpenOrCreate))

Dim xmlSer As System.Xml.Serialization.XmlSerializer = New
System.Xml.Serialization.XmlSerializer(test.GetType())

xmlSer.Serialize(sw, test)

End Function


and this is the error:
System.IO.FileNotFoundException: ?
File name: "-pfa3ijp.dll"
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String
codeBase, Boolean isStringized, Evidence assemblySecurity, Boolean
throwOnFileNotFound, Assembly locationHint, StackCrawlMark& stackMark)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef,
Boolean stringized, Evidence assemblySecurity, StackCrawlMark& stackMark)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef, Evidence
assemblySecurity)
at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()
at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()
at System.Xml.Serialization.Compiler.Compile()
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings)
at
System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlTypeMapping
xmlTypeMapping)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String
defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type)
at WebService1.Service1.HelloWorld() in
c:\inetpub\wwwroot\WebService1\Service1.asmx.vb:line 64

=== Pre-bind state information ===
LOG: Where-ref bind. Location = C:\WINDOWS\TEMP\-pfa3ijp.dll
LOG: Appbase = file:///c:/inetpub/wwwroot/WebService1
LOG: Initial PrivatePath = bin
Calling assembly : (Unknown).
===

LOG: Policy not being applied to reference at this time (private, custom,
partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/WINDOWS/TEMP/-pfa3ijp.dll.

please note that the aspnet user has full right on windows\temp.

Tu-Thach said:
The reason I suggest that you use database/file for this is because of
your requirement: ...should not be cleared even against machine reboot. As
for the XmlSerializer, I don't know what you are doing to pinpoint the
problem. Maybe you can post your code snippet.
 
P

Paolo Liverani

Thank you Luke,
that's almost what I'm doing but the problem is in the xmlserialization (see
my last post to Tu-Thach).
Paolo Liverani
 
P

Paolo Liverani

Hi Steven,
that's a really good snippet but how can I handle an ArrayList of
arrays?
Paolo
 
S

Steven Cheng[MSFT]

Hi Paolo,


Thanks for your response. Does the "ArrayList of arrarys" means an
ArrayList which contains some certain class's instance's arraies? If so, I
think that's Also ok, the only key point is that you must specify which
type of memeber(Array) will be contained in the ArrayList as I've mentioned
in the last reply. You may view the tech reference I provided in the last
reply for detailed description on those xml attributes.
In addition, another approach is to define some certain classes, each of
them has a member , the member is a certain class's object array. Then, you
can add these certain classes into the ArrayList rather then directly those
arraies, do you think so?


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
P

Paolo Liverani

Hi Steven,
I have read the documentation you have pointed me to but I cannot solve my
problem.
Can you give an example tailored with the following variable type:

Public arrayOfArrayList(10) As ArrayList

and tell me how can I specify the data type of each array's element (and,
recursively, the data type of each arrayList element)?
Thank you
Paolo
 
S

Steven Cheng[MSFT]

Hi Paolo,


Thanks for your followup. Does the Public arrayOfArrayList(10) As ArrayList
and "recursively, the data type of each arrayList element)?" means the
certain class have an ArrayList member, this
ArrayList's items are also ArrayLists, these element ArrayLists will
contain a certain type of object each?

If so, how many types of objects(how many kind of sub ArrayLists) will the
Main ArrayList contain? If not many, I think you can define some certain
classes which implements th ICollection interface and can be used as an
ArrayList. For example:
Public Class Employees
Implements ICollection
Public CollectionName As String
Private empArray As ArrayList = new ArrayList()

Public ReadOnly Default Overloads _
Property Item(index As Integer) As Employee
get
return CType (empArray(index), Employee)
End Get
End Property

Public Sub CopyTo(a As Array, index As Integer) _
Implements ICollection.CopyTo
empArray.CopyTo(a, index)
End Sub

Public ReadOnly Property Count () As integer Implements _
ICollection.Count
get
Count = empArray.Count
End Get

End Property

Public ReadOnly Property SyncRoot ()As Object _
Implements ICollection.SyncRoot
get
return me
End Get
End Property

Public ReadOnly Property IsSynchronized () As Boolean _
Implements ICollection.IsSynchronized
get
return false
End Get
End Property


Public Function GetEnumerator() As IEnumerator _
Implements IEnumerable.GetEnumerator

return empArray.GetEnumerator()
End Function

Public Function Add(newEmployee As Employee) As Integer
empArray.Add(newEmployee)
return empArray.Count
End Function
End Class
-----------------------
This is the sample in MSDN

Then let the top-level ArrayList contains such class's object instances.
and use XmlArray Attribute to specify these classes for the item elements
of the top-level ArrayList so as to correctly serialize it. How do you
think of this? I'll try making a simple sample to show the above means and
will update you as soon as possible.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
S

Steven Cheng[MSFT]

Hi Paolo,

Thank you for the response. Regarding on the issue, I am
finding proper resource to assist you and we will update as soon as posible.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security(This posting is provided "AS IS",
with no warranties, and confers no rights.)
 
S

Steven Cheng[MSFT]

Hi Paolo,

Thanks for your followup. After further researching ,I did found that
there're something wrong with the Serializer, not simply the code's
problem. In fact, I stratch the sample from the MSDN's code. I'm still not
sure on the detailed causes. So currrently I've used another way to
implement the class structure as:
root class contain an ArrayList
then ArrayList can contain multi-instances of a class which implementing
the ICollection interface and can perform as an ArrayList which contain
members of a certain class.

I've attached the modifid project in this message. Please check it out.
Thanks.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
P

Paolo Liverani

Thank you for the sample Steven.
Anyway, is that a bug in serialization or what else?
Paolo
 
S

Steven Cheng[MSFT]

Hi Paolo,

Thanks for the followup. I can't assure whether this is a bug. Anyway,
There does exist some mistakes in the MSDN's sample code( I originally
scratch the sample from it), it doesn't apply the correct Serialization
Attribute. Or maybe it hasn't expect the situation that we'll apply that
on a class that has hierarchical arraylists. :). Thanks again for your
noticing.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top