Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post Not Returning Response #20

Open
GhstTracker opened this issue Apr 29, 2014 · 0 comments
Open

Post Not Returning Response #20

GhstTracker opened this issue Apr 29, 2014 · 0 comments

Comments

@GhstTracker
Copy link

I am having an issue where a post WebApi method is not returning a response to the consuming client.

The client is another controller in the same solution/website (for testing purposes)

When I remove the Authorize attribute from the Post method everything works as expected and I recieve the response from the post method.
Client Method calling the post method

        Dim postUri As String = "1/client/DataXChangeTester/type/CollisionReport"

        Dim leftChild As New QueryNode With {.NodeValue = "drivers.name.lastName"}
        Dim rightChild As New QueryNode With {.NodeValue = "McNear"}

        Dim simpleOperation As New QueryNode With {.NodeValue = "is",
                                                  .LeftNode = leftChild,
                                                   .RightNode = rightChild}

        Dim queryToSend As QueryDetails = New QueryDetails With {.QueryDetail = simpleOperation}

        TesterClient = New HttpClient(HawkClientHandler)
        'TesterClient = New HttpClient()
        Dim webAddress As String = ConfigurationManager.AppSettings("ServiceURL")
        TesterClient.BaseAddress = New Uri(webAddress)

        TesterClient.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))

        Dim action = TesterClient.PostAsync(postUri, queryToSend, New JsonMediaTypeFormatter())

        '30 second timeout.
        action.Wait(30000)


        Dim response As HttpResponseMessage = action.Result

        If response.IsSuccessStatusCode Then
            ViewData("PredefinedQueryMessage") = response.Content.ReadAsStringAsync().Result
            Return View("Index")
        Else
            ViewData("PreDefinedQueryErrorMessage") = response.Content.ReadAsStringAsync().Result
            Return View("Index")
        End If

Client credential and message handler setup

 TestCredential = New HawkCredential With {
            .Id = "BuyCrashTN",
            .Algorithm = "sha256",
            .Key = "1531d118-ae19-11e3-b324-28cfe9215d9f"}

        HawkClientHandler = New HawkClientMessageHandler(New HttpClientHandler(), TestCredential)

Server side code

WEBApiConfig

 Dim handler As New HawkMessageHandler(New HttpControllerDispatcher(config),
                                              Function(credential)
                                                  Return Task.FromResult(RetrieveCredential(credential))
                                              End Function)

Post Method

 'POST 'api/1/client/ClientName/type/TypeName
    <Authorize>
    <AcceptVerbs("POST")>
    Public Function Query(requestMessage As HttpRequestMessage,
                          clientId As String,
                          typeName As String,
                          <FromBody> requestedQuery As QueryDetails) As HttpResponseMessage
        Dim responseContents As New QueryResults()
        Dim response As HttpResponseMessage
        Dim requestId As Integer = -1
        Try
            requestId = LogRequest("Received Query", requestedQuery)
            ReportType = GetType(DataXChangeCollisionQuery)
            Parameter = Expression.Parameter(ReportType, "report")
            responseContents = ExecuteQuery(requestedQuery)
            response = requestMessage.CreateResponse(HttpStatusCode.OK, responseContents)
        Catch ex As Exception
            response = requestMessage.CreateErrorResponse(HttpStatusCode.InternalServerError, "Error Processing Provided Query")
        End Try
        LogRequest("Exiting Query Operation", requestedQuery, requestId)

        Return response
    End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant