What data types are SOAP serializable

X

xmail123

Hi,

As was pointed out whatever you return from a WebMethod needs to be
serializable to SOAP. An ArrayList is not serializable. I will be
needing to return other data types from web methods. Is there a
document, or can some one list those types that are not serializable
and the syntax for converting them?

Thanks
Whatever you return from a WebMethod needs to be serializable to SOAP. The
type ArrayList is not serializable to SOAP so it gets converted to an array
of objects (object[]) which is SOAP serializable (provided the objects in
the array are SOAP serializable).
2. What do I need to do to get an ArrayList on the receiving side? I
need to be able to resize the array. An Array can't be resized, the
ArrayList can.

ArrayList al = new ArrayList(WSR.ReadHistory(ItemPK));

Regards,
Sami
 
S

Sahil Malik

My guess is, since Soap is nothing but SoapFormatter, anything that
implements ISerializable should be soap - serializable .. so arraylist
isn't, but HashTable is.

Or you could create a SerializableArrayList by inheriting from ArrayList,
and implementing ISerializable (or something like that).

- Sahil Malik
Independent Consultant
You can reach me thru my blog at -
http://www.dotnetjunkies.com/weblog/sahilmalik/



Hi,

As was pointed out whatever you return from a WebMethod needs to be
serializable to SOAP. An ArrayList is not serializable. I will be
needing to return other data types from web methods. Is there a
document, or can some one list those types that are not serializable
and the syntax for converting them?

Thanks
Whatever you return from a WebMethod needs to be serializable to SOAP. The
type ArrayList is not serializable to SOAP so it gets converted to an array
of objects (object[]) which is SOAP serializable (provided the objects in
the array are SOAP serializable).
2. What do I need to do to get an ArrayList on the receiving side? I
need to be able to resize the array. An Array can't be resized, the
ArrayList can.

ArrayList al = new ArrayList(WSR.ReadHistory(ItemPK));

Regards,
Sami
 
J

John Wood

Actually a hashtable isn't serializable through soap.

Sahil Malik said:
My guess is, since Soap is nothing but SoapFormatter, anything that
implements ISerializable should be soap - serializable .. so arraylist
isn't, but HashTable is.

Or you could create a SerializableArrayList by inheriting from ArrayList,
and implementing ISerializable (or something like that).

- Sahil Malik
Independent Consultant
You can reach me thru my blog at -
http://www.dotnetjunkies.com/weblog/sahilmalik/



Hi,

As was pointed out whatever you return from a WebMethod needs to be
serializable to SOAP. An ArrayList is not serializable. I will be
needing to return other data types from web methods. Is there a
document, or can some one list those types that are not serializable
and the syntax for converting them?

Thanks
Whatever you return from a WebMethod needs to be serializable to SOAP. The
type ArrayList is not serializable to SOAP so it gets converted to an array
of objects (object[]) which is SOAP serializable (provided the objects in
the array are SOAP serializable).

2. What do I need to do to get an ArrayList on the receiving side? I
need to be able to resize the array. An Array can't be resized, the
ArrayList can.

ArrayList al = new ArrayList(WSR.ReadHistory(ItemPK));

Regards,
Sami
 
S

Sahil Malik

// Actually hashtable is serializable thru soap ... formatter is a
formatter.

using System;
using System.IO ;
using System.Collections ;
using System.Runtime.Serialization ;
using System.Runtime.Serialization.Formatters.Soap ;

namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Hashtable hsh = new Hashtable() ;

hsh.Add("Add an intrinsic",1) ;
hsh.Add("Add an object",new
System.Data.DataTable("unserializable_datatable")) ;
hsh.Add("It does work", DateTime.Now) ;

Stream stream = File.Open("c:\\trial.xml", FileMode.Create);
SoapFormatter formatter = new SoapFormatter() ;
formatter.Serialize(stream, hsh);
stream.Close();
}
}
}

trial.xml looks like -------->

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<a1:Hashtable id="ref-1"
xmlns:a1="http://schemas.microsoft.com/clr/ns/System.Collections">
<LoadFactor>0.72</LoadFactor>
<Version>3</Version>
<Comparer xsi:null="1"/>
<HashCodeProvider xsi:null="1"/>
<HashSize>11</HashSize>
<Keys href="#ref-2"/>
<Values href="#ref-3"/>
</a1:Hashtable>
<SOAP-ENC:Array id="ref-2" SOAP-ENC:arrayType="xsd:anyType[3]">
<item id="ref-4" xsi:type="SOAP-ENC:string">Add an intrinsic</item>
<item id="ref-5" xsi:type="SOAP-ENC:string">Add an object</item>
<item id="ref-6" xsi:type="SOAP-ENC:string">It does work</item>
</SOAP-ENC:Array>
<SOAP-ENC:Array id="ref-3" SOAP-ENC:arrayType="xsd:anyType[3]">
<item xsi:type="xsd:int">1</item>
<item href="#ref-7"/>
<item xsi:type="xsd:dateTime">2004-06-18T11:23:31.2857751-04:00</item>
</SOAP-ENC:Array>
<a3:DataTable id="ref-7"
xmlns:a3="http://schemas.microsoft.com/clr/nsassem/System.Data/System.Data%2
C%20Version%3D1.0.5000.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Db77a5c
561934e089">
<XmlSchema id="ref-9"><?xml version="1.0"
encoding="utf-16"?>
<xs:schema id="tmpDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="unserializable_datatable">
<xs:complexType>
</xs:complexType>
</xs:element>
<xs:element name="tmpDataSet"
msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded" />
</xs:complexType>
</xs:element>
</xs:schema></XmlSchema>
<XmlDiffGram id="ref-10"><diffgr:diffgram
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
/></XmlDiffGram>
</a3:DataTable>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


- Sahil Malik
Independent Consultant
You can reach me thru my blog - http://dotnetjunkies.com/WebLog/sahilmalik/



John Wood said:
Actually a hashtable isn't serializable through soap.

Sahil Malik said:
My guess is, since Soap is nothing but SoapFormatter, anything that
implements ISerializable should be soap - serializable .. so arraylist
isn't, but HashTable is.

Or you could create a SerializableArrayList by inheriting from ArrayList,
and implementing ISerializable (or something like that).

- Sahil Malik
Independent Consultant
You can reach me thru my blog at -
http://www.dotnetjunkies.com/weblog/sahilmalik/



Hi,

As was pointed out whatever you return from a WebMethod needs to be
serializable to SOAP. An ArrayList is not serializable. I will be
needing to return other data types from web methods. Is there a
document, or can some one list those types that are not serializable
and the syntax for converting them?

Thanks

Whatever you return from a WebMethod needs to be serializable to
SOAP.
The
type ArrayList is not serializable to SOAP so it gets converted to an array
of objects (object[]) which is SOAP serializable (provided the
objects
 
J

John Wood

oh weird, maybe my memory is failing me.
Was this always the case? (net 1.0 also?)
I definitely had *some* kinda problem with hashtable serialization with
either soap or binary formatters.
Unless I'm..losing..my...mind..

Sahil Malik said:
// Actually hashtable is serializable thru soap ... formatter is a
formatter.

using System;
using System.IO ;
using System.Collections ;
using System.Runtime.Serialization ;
using System.Runtime.Serialization.Formatters.Soap ;

namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Hashtable hsh = new Hashtable() ;

hsh.Add("Add an intrinsic",1) ;
hsh.Add("Add an object",new
System.Data.DataTable("unserializable_datatable")) ;
hsh.Add("It does work", DateTime.Now) ;

Stream stream = File.Open("c:\\trial.xml", FileMode.Create);
SoapFormatter formatter = new SoapFormatter() ;
formatter.Serialize(stream, hsh);
stream.Close();
}
}
}

trial.xml looks like -------->

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<a1:Hashtable id="ref-1"
xmlns:a1="http://schemas.microsoft.com/clr/ns/System.Collections">
<LoadFactor>0.72</LoadFactor>
<Version>3</Version>
<Comparer xsi:null="1"/>
<HashCodeProvider xsi:null="1"/>
<HashSize>11</HashSize>
<Keys href="#ref-2"/>
<Values href="#ref-3"/>
</a1:Hashtable>
<SOAP-ENC:Array id="ref-2" SOAP-ENC:arrayType="xsd:anyType[3]">
<item id="ref-4" xsi:type="SOAP-ENC:string">Add an intrinsic</item>
<item id="ref-5" xsi:type="SOAP-ENC:string">Add an object</item>
<item id="ref-6" xsi:type="SOAP-ENC:string">It does work</item>
</SOAP-ENC:Array>
<SOAP-ENC:Array id="ref-3" SOAP-ENC:arrayType="xsd:anyType[3]">
<item xsi:type="xsd:int">1</item>
<item href="#ref-7"/>
<item xsi:type="xsd:dateTime">2004-06-18T11:23:31.2857751-04:00</item>
</SOAP-ENC:Array>
<a3:DataTable id="ref-7"
xmlns:a3="http://schemas.microsoft.com/clr/ns...000.0, Culture=neutral, PublicKeyToken=b77a5c
561934e089">
<XmlSchema id="ref-9"><?xml version="1.0"
encoding="utf-16"?>
<xs:schema id="tmpDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="unserializable_datatable">
<xs:complexType>
</xs:complexType>
</xs:element>
<xs:element name="tmpDataSet"
msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded" />
</xs:complexType>
</xs:element>
</xs:schema></XmlSchema>
<XmlDiffGram id="ref-10"><diffgr:diffgram
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
/></XmlDiffGram>
</a3:DataTable>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


- Sahil Malik
Independent Consultant
You can reach me thru my blog - http://dotnetjunkies.com/WebLog/sahilmalik/



John Wood said:
Actually a hashtable isn't serializable through soap.

Sahil Malik said:
My guess is, since Soap is nothing but SoapFormatter, anything that
implements ISerializable should be soap - serializable .. so arraylist
isn't, but HashTable is.

Or you could create a SerializableArrayList by inheriting from ArrayList,
and implementing ISerializable (or something like that).

- Sahil Malik
Independent Consultant
You can reach me thru my blog at -
http://www.dotnetjunkies.com/weblog/sahilmalik/



Hi,

As was pointed out whatever you return from a WebMethod needs to be
serializable to SOAP. An ArrayList is not serializable. I will be
needing to return other data types from web methods. Is there a
document, or can some one list those types that are not serializable
and the syntax for converting them?

Thanks

Whatever you return from a WebMethod needs to be serializable to SOAP.
The
type ArrayList is not serializable to SOAP so it gets converted to an
array
of objects (object[]) which is SOAP serializable (provided the
objects
in
the array are SOAP serializable).

2. What do I need to do to get an ArrayList on the receiving
side?
 
M

Mickey Williams

Instances of Hashtable are not serializable through a .asmx web service
page, because it uses XML serialization. You can use the SoapFormatter class
to serialize an arbitrary graph, but that's not the same thing.
 
M

Mickey Williams

Sahil Malik said:
My guess is, since Soap is nothing but SoapFormatter, anything that
implements ISerializable should be soap - serializable .. so arraylist
isn't, but HashTable is.

This is not correct. The implementation of .asmx web services uses XML
serialization, not the SoapFormatter class and runtime serialization.
ISerializable has nothing to do with the XML serialization process.
 
M

Mickey Williams

There is some confusion in this thread between full-fidelity runtime
serialization (which enlists the SoapFormatter or BinaryFormatter) and XML
serialization used by web services, which uses the XmlSerializer class.

An instance of ArrayList is certainly serializable with the XML serializer,
and therefore via an XML web method, as any simple experiment will
demonstrate. The response quoted by the OP is incorrect in several ways.

If you publish the web method and then consume it via a web reference, it
will be transformed into an array of object, but this has everything to do
with XML schema and the way that ArrayList is typed, and nothing to do with
ArrayList not being XML serializable. Since ArryaList is a universal donor
and acceptor of type object, its equivalent XML schema is a sequence of
xs:any. When Visual Studio sees a web service that includes a sequence of
xs:any, it turns it into an array of object. If you use a tracing tool (like
SoapScope or something similar), you'll see that the elements in the array
are serialized over the wire.

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com/blogs/mickey


Hi,

As was pointed out whatever you return from a WebMethod needs to be
serializable to SOAP. An ArrayList is not serializable. I will be
needing to return other data types from web methods. Is there a
document, or can some one list those types that are not serializable
and the syntax for converting them?

Thanks
Whatever you return from a WebMethod needs to be serializable to SOAP. The
type ArrayList is not serializable to SOAP so it gets converted to an array
of objects (object[]) which is SOAP serializable (provided the objects in
the array are SOAP serializable).
2. What do I need to do to get an ArrayList on the receiving side? I
need to be able to resize the array. An Array can't be resized, the
ArrayList can.

ArrayList al = new ArrayList(WSR.ReadHistory(ItemPK));

Regards,
Sami
 

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

Top