// 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
ataTable 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
ataTable>
</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?