Hello everyone,
I am new to web API and i need to implement a call back url for a web service.I am able to post a request to the uri and receive a json response from the post.
I am expected to implement a callback to receive the status of my transaction in order to update my transaction accordingly. I have been on this for days now as i am unable to get the values posted to my callback function.
Here are my codes. Please help me, what am i doing wrong?
What I have tried:
Here is my class
<pre lang="VB">
Public Class MyCallback
Public Property responseCode As String
Public Property responseMessage As String
Public Property TransactionId As String
Public Property networkTransactionId As String
Public Property merchantId As String
Public Property productId As String
Public Property refNo As String
Public Property msisdn As String
Public Property amount As String
Public Property timestamp As String
Public Property balance As String
End Class
Then here is my implementation in StudentsController. I intend to get the values from the <frombody> attribute and use them implement my ADO.Net code.
<pre>Public Function PostCallback(<FromBody> ByVal ITC As MyCallback) As HttpResponseMessage
Dim Exists As Integer = ValidateTransactionNumber(ITC.refNo)
If Exists = 0 Then
Return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid reference")
Else
Try
Dim command As New SqlCommand("us_update_transaction_with_callback", connection)
command.CommandType = CommandType.StoredProcedure
command.Parameters.AddWithValue("@ResponseCode", Request.Content())
command.Parameters.AddWithValue("@ResponseMsg", ITC.responseMessage)
command.Parameters.AddWithValue("@APITransID", ITC.TransactionId)
command.Parameters.AddWithValue("@MerchantID", ITC.merchantId)
command.Parameters.AddWithValue("@NetworkTransID", ITC.networkTransactionId)
command.Parameters.AddWithValue("@PaymentCode", ITC.refNo)
command.Parameters.AddWithValue("@PhoneNumber", ITC.msisdn)
command.Parameters.AddWithValue("@Amount", ITC.amount)
command.Parameters.AddWithValue("@Timestamp", ITC.timestamp)
command.Parameters.AddWithValue("@Balance", ITC.balance)
If connection.State = ConnectionState.Closed Then
connection.Open()
End If
command.ExecuteNonQuery()
connection.Close()
Return Request.CreateResponse(HttpStatusCode.OK, "Callback completed successfully")
Catch ex As Exception
Return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)
End Try
End If
End Function
When i test in Postman, i get the following error
{"Message":"No mapping exists from object type System.Web.Http.WebHost.HttpControllerHandler+LazyStreamContent to a known managed provider native type."}