S A M P L E S
Converting
between value object types with different namespaces
Since SOAP value objects are defined within a WSDL, the same value object
types can be generated in different namespaces. SOAP
proxies and value objects must have the same namespace to be used together.
This often presents a problem when devising
solutions that use dynamic ArcGIS Server value objects you have generated
and ArcGIS Server value objects in another product for which you cannot
change the namespace. For example, assume
you generate a set of dynamic value objects with the namespace "wsmap".
If you create a wsmap.Envelope and attempt
to use it with an ESRI.ArcGIS.ADF.ArcGISServer.SpatialFilter (included
with the ArcGIS Server Web ADF) by assigning it
to the FilterGeometry property, a compile time error will occur. In
general, the types are different because the namespaces are different.
If you have complete control over the generation
of SOAP proxies and value objects, you can generate value object types
that can be shared across ArcGIS Server service types (e.g. PolygonN is
included with every ArcGIS Server service type). If
you are unable to modify the namespace for SOAP proxies and value objects,
you can use the following code to convert between namespaces. In
the example, a PolylineN created dynamically is being converted to an
ESRI.ArcGIS.ADF.ArcGISServer.PolylineN. The
.NET System.Xml.Serialization.XmlSerializer is used to serialize and deserialize
the SOAP value object to and from a string.
// Serialize value object into SOAP string
Type valueType = dynamicSoapPolylineN.GetType();
System.Xml.Serialization.XmlSerializer xmlSerializer =
new
System.Xml.Serialization.XmlSerializer(valueType);
System.Text.StringBuilder stringBuilder = new StringBuilder();
System.IO.StringWriter stringWriter = new System.IO.StringWriter(stringBuilder);
xmlSerializer.Serialize(stringWriter, dynamicSoapPolylineN);
string soapSerializedValueObject = stringBuilder.ToString();
// Read SOAP string to deserialize to same type, different namespace
System.Xml.XmlTextReader xmlTextReader =
new System.Xml.XmlTextReader(new System.IO.StringReader(soapSerializedValueObject));
System.Xml.Serialization.XmlSerializer mySerializer = new
System.Xml.Serialization.XmlSerializer
(typeof(ESRI.ArcGIS.ADF.ArcGISServer.PolylineN));
object newValueObject = mySerializer.Deserialize(xmlTextReader);
ESRI.ArcGIS.ADF.ArcGISServer.PolylineN adfSoapPolylineN =
(ESRI.ArcGIS.ADF.ArcGISServer.PolylineN)newValueObject;