示例#1
0
        private Response Receive(WebResponse webResponse)
        {
            Response response = null;
            Error    error    = null;

            try
            {
                // open the response stream; if debugging or tracing, read the stream
                // into a string for display then open an XmlReader on the string,
                // otherwise open an XmlReader directly on the stream

                Stream        stream = webResponse.GetResponseStream();
                XmlTextReader xmlTextReader;

                if (LoggingEnabled)
                {
                    StreamReader streamReader   = new StreamReader(stream, new UTF8Encoding(false));
                    string       responseString = streamReader.ReadToEnd();

                    Log(String.Format("{0}  --  ArcXML Response\n\n", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")));
                    Log(responseString + "\n\n");

                    xmlTextReader = new XmlTextReader(new StringReader(responseString));
                }
                else
                {
                    xmlTextReader = new XmlTextReader(stream);
                }

                ArcXmlReader reader = new ArcXmlReader(xmlTextReader);

                // handle an error response from the Application Server

                if (reader.Name == Error.XmlName)
                {
                    error = Error.ReadFrom(reader);
                    throw new ArcImsException("ArcIMS Application Server - " + error.Text);
                }

                // move to the specific response element and deserialize it

                reader.MoveToResponse();

                switch (reader.Name)
                {
                case ServiceInfo.XmlName: response = ServiceInfo.ReadFrom(reader); break;

                case Image.XmlName: response = Image.ReadFrom(reader); break;

                case Layout.XmlName: response = Layout.ReadFrom(reader); break;

                case Geocode.XmlName: response = Geocode.ReadFrom(reader); break;

                case Features.XmlName: response = Features.ReadFrom(reader); break;

                case Services.XmlName: response = Services.ReadFrom(reader); break;

                case Error.XmlName:
                    error = Error.ReadFrom(reader);
                    throw new ArcImsException("ArcIMS Spatial Server - " + error.Text);

                default:
                    throw new ArcImsException("Unsupported ArcXML response received from ArcIMS server: " + reader.Name);
                }
            }
            catch (Exception ex)
            {
                if (ex is ArcImsException)
                {
                    throw ex;
                }
                else
                {
                    throw new ArcImsException("Could not receive ArcXML response", ex);
                }
            }
            finally
            {
                webResponse.Close();
            }

            return(response);
        }