Skip to content

WmsClient

Namespace: ThinkGeo.Core

A complete WMS request client and nothing else: capabilities, format negotiation and GetMap URL construction, with no Layer, no canvas and no drawing. WmsAsyncLayer is a Layer that renders what a client like this fetches; a tile source that only needs the protocol talks to this class.

public sealed class WmsClient : IWmsEntity

Inheritance object → WmsClient
Implements IWmsEntity

Remarks:

The protocol knowledge itself lives one level lower and is shared: reads GetCapabilities and WmsUtil builds request URLs, for this client and for the layer alike.

Properties

ActiveLayerNames

The layer names to request, bottom one first.

public Collection<string> ActiveLayerNames { get; }

Property Value

Collection<string>

ActiveStyleNames

The style to request for each entry of WmsClient.ActiveLayerNames, in the same order.

public Collection<string> ActiveStyleNames { get; }

Property Value

Collection<string>

Uri

The service endpoint.

public Uri Uri { get; set; }

Property Value

Uri

IsTransparent

Whether the server should draw the map on a transparent background.

public bool IsTransparent { get; set; }

Property Value

bool

OutputFormat

The image MIME type to request. PNG until the capabilities negotiation replaces it.

public string OutputFormat { get; set; }

Property Value

string

WebProxy

The proxy to reach the server through.

public IWebProxy WebProxy { get; set; }

Property Value

IWebProxy

TimeoutInSeconds

How long a request may take before it is abandoned. Twenty seconds by default.

public int TimeoutInSeconds { get; set; }

Property Value

int

Crs

The coordinate reference system to request the map in.

public string Crs { get; set; }

Property Value

string

Exceptions

The format the server should report errors in, its EXCEPTIONS parameter.

public string Exceptions { get; set; }

Property Value

string

Parameters

Extra query-string parameters added to every request.

public Dictionary<string, string> Parameters { get; }

Property Value

Dictionary<string, string>

AxisOrder

How the bounding box axes are ordered in a request. The default lets the version and the CRS decide.

public WmsAxisOrder AxisOrder { get; set; }

Property Value

WmsAxisOrder

FastMode

True skips GetCapabilities entirely: requests go straight to WmsClient.Uri with the format and version the caller set.

public bool FastMode { get; set; }

Property Value

bool

Version

The WMS version to speak. WmsClient.OpenAsync(CancellationToken) replaces it with the version the server declares.

public string Version { get; set; }

Property Value

string

UserAgent

The User-Agent header sent with each request.

public string UserAgent { get; set; }

Property Value

string

Credentials

The credentials for a server that requires authentication.

public ICredentials Credentials { get; set; }

Property Value

ICredentials

CapabilitiesCacheTimeout

How long a parsed GetCapabilities response is reused before it is fetched again. Ten minutes by default.

public TimeSpan CapabilitiesCacheTimeout { get; set; }

Property Value

TimeSpan

IsOpen

Whether WmsClient.OpenAsync(CancellationToken) has completed.

public bool IsOpen { get; private set; }

Property Value

bool

Constructors

WmsClient(Uri, string, WmsAxisOrder, string, bool)

Creates a client for a WMS endpoint.

public WmsClient(Uri uri, string crs, WmsAxisOrder axisOrder, string version, bool fastMode)

Parameters

uri Uri
The service endpoint.

crs string
The coordinate reference system to request the map in.

axisOrder WmsAxisOrder
How the bounding box axes are ordered in a request.

version string
The WMS version to speak until the server declares its own.

fastMode bool
True to skip GetCapabilities; see .

Methods

GetServerLayers()

The layers the server publishes, with their titles, scale ranges and extents.

public Collection<WmsServerLayer> GetServerLayers()

Returns

Collection<WmsServerLayer>
A copy of the layer list; changing it does not change what is requested.

Exceptions

InvalidOperationException
The client is not open, or was opened in fast mode.

Remarks:

Read from the GetCapabilities response this client already parses when it opens, so asking costs nothing. Until this existed the answer was reachable only through WmsAsyncLayer, which left anything driving the protocol directly - a GPU raster tile source, say - with no way to find out what a server offers. https://community.thinkgeo.com/t/wms-wfs-feedback-wishes/12476

GetServerLayerNames()

The names of the layers the server publishes, ready for WmsClient.ActiveLayerNames.

public Collection<string> GetServerLayerNames()

Returns

Collection<string>
A copy of the name list.

Exceptions

InvalidOperationException
The client is not open, or was opened in fast mode.

GetServerStyleNames()

The style names the server publishes, ready for WmsClient.ActiveStyleNames.

public Collection<string> GetServerStyleNames()

Returns

Collection<string>
A copy of the name list.

Exceptions

InvalidOperationException
The client is not open, or was opened in fast mode.

GetServerOutputFormats()

The image formats the server can answer GetMap in, ready for WmsClient.OutputFormat.

public Collection<string> GetServerOutputFormats()

Returns

Collection<string>
A copy of the format list.

Exceptions

InvalidOperationException
The client is not open, or was opened in fast mode.

GetServerFeatureInfoFormats()

The formats the server can answer GetFeatureInfo in.

public Collection<string> GetServerFeatureInfoFormats()

Returns

Collection<string>
A copy of the format list.

Exceptions

InvalidOperationException
The client is not open, or was opened in fast mode.

GetServerCrsNames()

The coordinate systems the server can answer in, ready for WmsClient.Crs.

public Collection<string> GetServerCrsNames()

Returns

Collection<string>
A copy of the CRS list.

Exceptions

InvalidOperationException
The client is not open, or was opened in fast mode.

OpenAsync(CancellationToken)

Fetches and parses GetCapabilities (unless WmsClient.FastMode), adopts the server's version and negotiates the output format.

public Task OpenAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task

GetRequestUrl(RectangleShape, int, int)

Builds the GetMap URL for one extent - the same construction the layer uses, through the same WmsUtil.

public string GetRequestUrl(RectangleShape worldExtent, int width, int height)

Parameters

worldExtent RectangleShape

width int

height int

Returns

string

Events

SendingHttpRequest

Raised before the capabilities request this client makes when it opens. Rewrite the request to add an API key, a signed URL or authentication headers; set Cancel to skip it. The GPU tile sources forward their own SendingHttpRequest here, so one subscription on a source covers its capabilities request and its tiles. https://community.thinkgeo.com/t/wmsrastertilesource-wmtsrastertilesource-and-authentication/12470

public event EventHandler<SendingHttpRequestMessageEventArgs> SendingHttpRequest;