Please help am having a problem with returning values from webapi by passing parameters
When i run this URLCode:Imports System.Data.SqlClient Imports System.Net Imports System.Web.Http Namespace Controllers Public Class HandlerVBLoadtermController Inherits ApiController <Route("api/HandlerVBLoadterm/GetCustomersJSON/{customerid}/{customerid2}")> <HttpGet> Public Function GetCustomersJSON(customerId As String, customerId2 As String) As IHttpActionResult Dim customers As New List(Of Customer)() Using conn As New SqlConnection() conn.ConnectionString = ConfigurationManager.ConnectionStrings("KABOJJAConnectionString").ConnectionString Using cmd As New SqlCommand() cmd.CommandType = CommandType.StoredProcedure cmd.CommandText = "Gettermnew" cmd.Parameters.AddWithValue("@p", customerId) cmd.Parameters.AddWithValue("@s", customerId2) cmd.Connection = conn conn.Open() Using sdr As SqlDataReader = cmd.ExecuteReader() While sdr.Read() customers.Add(New Customer With { .Account = If(IsDBNull(sdr("Admno")), String.Empty, sdr("Admno")), .Expressed = If(IsDBNull(sdr("Expressed")), String.Empty, sdr("Expressed"))}) End While End Using conn.Close() End Using Return Ok(customers) End Using End Function End Class Public Class Customer Public Property Account() As String Public Property Expressed() As String End Class End Namespace
this returns Json data but when i runs this URL below with the ? operand it doesnot return any dataCode:http://192.168.14.205/KABOJJAAPPAPI/api/HandlerVBLoadterm/GetCustomersJSON/0782911364/Father
I get this error when i try to run itCode:http://192.168.14.205/KABOJJAAPPAPI/api/HandlerVBLoadterm/GetCustomersJSON?customerid=0782911364&customerid2=Father
Below is my webapi.config detailsCode:"No HTTP resource was found that matches the request URI 'http://192.168.14.205/KABOJJAAPPAPI/api/HandlerVBLoadterm/GetCustomersJSON?customerid=0782911364&customerid2=Father'."
Code:Imports System.Net.Http Imports System.Web.Http Imports Microsoft.Owin.Security.OAuth Imports Newtonsoft.Json.Serialization Public Module WebApiConfig Public Sub Register(config As HttpConfiguration) ' Web API configuration and services ' Configure Web API to use only bearer token authentication. config.SuppressDefaultHostAuthentication() config.Filters.Add(New HostAuthenticationFilter(OAuthDefaults.AuthenticationType)) ' Web API routes config.MapHttpAttributeRoutes() config.Routes.MapHttpRoute( name:="DefaultApi", routeTemplate:="api/{controller}/{id}", defaults:=New With {.id = RouteParameter.Optional} ) config.Formatters.Add(New CustomJSONFormatter()) ' Adding formatter for XML ' config.Formatters.XmlFormatter.MediaTypeMappings.Add(New QueryStringMapping("type", "xml", New MediaTypeHeaderValue("application/xml"))) End Sub End Module




Reply With Quote
