Click here to Skip to main content
15,884,177 members
Articles / Programming Languages / C#

Free Maps from the Web Using Web Mapping Service

Rate me:
Please Sign up or sign in to vote.
4.83/5 (52 votes)
20 Jun 2004CPOL27 min read 257.5K   8K   157  
Overview of using the OpenGIS Web Mapping Service to retrieve maps from the web
// $File: //depot/WMS/WMS Overview/Wms.Client/WmsException.cs $ $Revision: #1 $ $Change: 20 $ $DateTime: 2004/05/23 23:42:06 $

namespace Wms.Client
{
	/// <summary>
	/// Converts WMS exceptions returned from a WMS server as XML to .Net exceptions.
	/// </summary>
	public class WmsException : System.ApplicationException
	{
		internal WmsException(string exceptionFile) : base(Wms.Client.WmsException.extractMessage(exceptionFile))
		{
		}

		private static string extractMessage(string exceptionFile)
		{
			System.Text.StringBuilder retVal = new System.Text.StringBuilder();
			try
			{
				System.Xml.XPath.XPathDocument doc = new System.Xml.XPath.XPathDocument(exceptionFile);
				System.Xml.XPath.XPathNavigator nav = doc.CreateNavigator();
				System.Xml.XPath.XPathNodeIterator iter = nav.Select(@"/*/ServiceException");
				while (iter.MoveNext())
				{
					if (retVal.Length > 0)
						retVal.Append(System.Environment.NewLine);
					System.Xml.XPath.XPathNodeIterator attIter = iter.Current.Select(@"/code|/Code|/CODE");
					if (attIter.MoveNext())
					{
						retVal.Append("(" + iter.Current.Value.Trim() + ") ");
					}
					retVal.Append(iter.Current.Value.Trim());
				}
			}
			catch (System.Exception)
			{
				retVal.Append("Unable to extract the error description from the information returned by the WMS server.");
			}
			return retVal.ToString();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
Tom Gaskins is an independent software consultant currently providing technical assistance and software project management to NASA's Learning Technologies Office. The creation of this article was sponsored by NASA.

Comments and Discussions