Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JeffJacobson/3362569 to your computer and use it in GitHub Desktop.
Save JeffJacobson/3362569 to your computer and use it in GitHub Desktop.
ArcGIS Server 10.1 SOE output format bug workaround
/// <summary>
/// <para>ArcGIS Server 10.1 introduced a bug that causes the output format to always be set to "json"
/// even if another format (e.g., "xml") is specified via the "f" parameter in the HTTP request.
/// This method reads the "f" parameter from the <paramref name="operationInput"/> and sets the
/// <paramref name="outputFormat"/> to be the same value as the "f" parameter.</para>
/// <para>If there is no "f" parameter in <paramref name="operationInput"/> then
/// <paramref name="outputFormat"/> will retain its original value.</para>
/// </summary>
/// <param name="boundVariables"></param>
/// <param name="outputFormat"></param>
/// <example>
/// <code>
/// <![CDATA[public byte[] HandleRESTRequest(string Capabilities, string resourceName, string operationName, string operationInput, string outputFormat, string requestProperties, out string responseProperties)
/// {
/// // ArcGIS 10.1 bug workaround.
/// GetActualFormat(operationInput, ref outputFormat);
/// return _reqHandler.HandleRESTRequest(Capabilities, resourceName, operationName, operationInput, outputFormat, requestProperties, out responseProperties);
/// }]]>
/// </code>
/// </example>
private void GetActualFormat(string operationInput, ref string outputFormat)
{
if (string.IsNullOrEmpty(operationInput)) return;
var json = new JsonObject(operationInput);
GetActualFormat(json, ref outputFormat);
}
/// <summary>
/// <para>ArcGIS Server 10.1 introduced a bug that causes the output format to always be set to "json"
/// even if another format (e.g., "xml") is specified via the "f" parameter in the HTTP request.
/// This method reads the "f" parameter from the <paramref name="operationInput"/> and sets the
/// <paramref name="outputFormat"/> to be the same value as the "f" parameter.</para>
/// <para>If there is no "f" parameter in <paramref name="operationInput"/> then
/// <paramref name="outputFormat"/> will retain its original value.</para>
/// </summary>
/// <param name="boundVariables"></param>
/// <param name="outputFormat"></param>
/// <example>
/// <code>
/// <![CDATA[public byte[] HandleRESTRequest(string Capabilities, string resourceName, string operationName, string operationInput, string outputFormat, string requestProperties, out string responseProperties)
/// {
/// // ArcGIS 10.1 bug workaround.
/// GetActualFormat(operationInput, ref outputFormat);
/// return _reqHandler.HandleRESTRequest(Capabilities, resourceName, operationName, operationInput, outputFormat, requestProperties, out responseProperties);
/// }]]>
/// </code>
/// </example>
private void GetActualFormat(JsonObject operationInput, ref string outputFormat)
{
string f;
if (operationInput.TryGetString("f", out f))
{
outputFormat = f;
}
}
@JeffJacobson
Copy link
Author

Note that this workaround will not help you if you are trying to export HTML. For now, if you need to export HTML you can have the user specify a value other than html for f (e.g., htm or html5) and use this workaround.

@JeffJacobson
Copy link
Author

Example usage

public byte[] HandleRESTRequest(string Capabilities, string resourceName, string operationName, string operationInput, string outputFormat, string requestProperties, out string responseProperties)
{
     // ArcGIS 10.1 bug workaround.
     GetActualFormat(operationInput, ref outputFormat);
     return _reqHandler.HandleRESTRequest(Capabilities, resourceName, operationName, operationInput, outputFormat, requestProperties, out responseProperties);
}

@jnewmoyer
Copy link

You da man! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment