I was creating a new API App to support the Execution of Stored Procedures.

Instead of using the Document DB REST API, I decided to use the DocumentDB .NET API.  There is a tutorial, NoSQL tutorial: DocumentDB C# console application available on the Azure DocumentDB site.

My API has two methods:

  •  ExecuteStoredProcedureAsync
  •  GetStoredProcedureListAsync

I discovered an issue with the GetStoredProcedureListAsync operation in the NET API.  I was using the DocumentClient.ReadStoredProcedureAsync Method.

The following is the code I used to call this Method

/// <summary>
/// Get Stored Procedures List
/// </summary>
/// <remarks>Get an array of all stored procedures</remarks>
/// <returns>List of Stored Procedures</returns>
/// <response code="200">OK</response>
/// <response code="404">Not Found - This means the resource feed you tried to read did not exist.</response>
/// <response code="429">TooManyRequests - This means you have exceeded the number of request units per second. </response>
/// <response code="500">Internal Server Error</response>
/// <returns>FeedResponse</returns>
[Metadata("Get List of Stored Procedures")]
[Route("{DatabaseId}/colls/{CollectioId}/sprocs")]
[SwaggerOperation("GetStoredProcedureList")]
public async Task<FeedResponse<StoredProcedure>> GetStoredProcedureListAsync()
{
    FeedResponse<StoredProcedure> result;
    var continuation = string.Empty;
    do
    {
        // Read the feed 10 items at a time until there are no more items to read
        var response = await _documentDbContext.Client.ReadStoredProcedureFeedAsync(
            StoredProcedureLinkBase,
                new FeedOptions
                {
                    MaxItemCount = 10,
                    RequestContinuation = continuation
                });

        // Get the continuation so that we know when to stop.
        continuation = response.ResponseContinuation;

        result = response;

    } while (!string.IsNullOrEmpty(continuation));
    return result;
}

 


I built and published my API App.

Attachment Details

DocDbSPApi

I then created a new Web App in Visual Studio 2015 and used the “Add Rest API” as shown below.

App Service

Add REST App Service

The Azure App Service Activity results are shown below.

Azure App Service Activity

Azure App Service Activity Results

Adding REST API client had failed.

In order to track down the reason why,  I needed to view the Swagger.json file.

I  needed to go back to my  API APP on the Azure Portal,  and under Settings,  Select;  API Definition, as shown below.

API Setting

Settings

Once selected, I was able to  see the API definition location on the API Definition blade, as shown below.

API Definition

API Definition location

 


I copied the API definition location and opened it in Chrome.

The reason I use Chrome, is that you are able to view the JSON formatted.

Status Code Enumeration

Status Code Enumeration

The Response from the ReadStoredProcedureAsync Method includes the HttpStatusCode Enumeration. The Error Code Number is returned. The status of an HTTP request is contained in the HttpWebResponse.StatusCode property.

Normally this would not be a problem, but RestSharp generates Model Classes for the Response.

If you look at the JSON specification, you will see that enumerations must have unique values. You cannot have duplicates.

I wonder how many other operations in DocumentDB return the HttpStatusCode Enumeration?

Or even other Azure API’s?

In my next post, I will show how to fix the issue.