English

How To: Convert the SOAP Geometry object type between GeometryServer and MapServer namespaces

Summary

Calling the Buffer operation of a Geometry Service using the ArcGIS Server SOAP API returns the output buffer geometry under the geometry service namespace. When passing this geometry into the Spatial Filter under the map service namespace, a compile time error occurs. The happens because SOAP requires proxies and value objects must have the same namespace to be used together. In order to avoid this error, it is necessary to convert this geometry type from Geometry Service namespace into Map Service namespace by using .NET System.Xml.Serialization.XmlSerializer.

Procedure

  1. Convert the Geometry object returned from the Buffer method to a PolygonN type object.

    Code:
    GeometryServer.Geometry[] outputGeometry = geometryService.Buffer(inputSpatialReference, null, null, distances, linearUnit, false, inputGeometry);
    GeometryServer.PolygonN outputPolygon = (GeometryServer.PolygonN) outputGeometry[0];

  2. Serialize the value object into a SOAP string.

    Code:
    Type valueType = outputPolygon.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, outputPolygon);
    string soapSerializedValueObject = stringBuilder.ToString();

  3. Read the SOAP string to deserialize to the same type, different namespace.

    Code:
    System.Xml.XmlTextReader xmlTextReader =new System.Xml.XmlTextReader(new System.IO.StringReader(soapSerializedValueObject));
    System.Xml.Serialization.XmlSerializer mySerializer = new System.Xml.Serialization.XmlSerializer(typeof(MapServer.PolygonN));
    object newValueObject = mySerializer.Deserialize(xmlTextReader);
    MapServer.PolygonN newPolygonN = (MapServer.PolygonN)newValueObject;

  4. Apply the new PolygonN object into the SpatialFilter.

    Code:
    SpatialFilter sf = new SpatialFilter();
    sf.FilterGeometry = newPolygonN;

Related Information