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

相关信息
Article ID: 40758
Software:
ArcGIS Server (10.0 and prior) 10
ArcGIS for Server 10.1
Platforms:
Windows Windows 7

问题描述
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.
已邀请:

易智瑞技术支持

赞同来自:

解决方案

    1. Convert the Geometry object returned from the Buffer method to a PolygonN type object. 
    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. 
    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. 
    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. 
    SpatialFilter sf = new SpatialFilter();
    sf.FilterGeometry = newPolygonN;

    其它相关参考
    1. Converting between value object types with different namespaces


    创建及修改时间
    Created: 12/19/2012

    Last Modified: 1/3/2013
    原文链接
    http://support.esri.com/en/kno ... 40758

    要回复问题请先登录注册