Hi All,
I'm trying to get a little webapi running, but I am stuck with an error I get when trying to get data from my service using a passed parameter. The error I get is a null object reference somewhere in the underlying dll's:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.Http.WebHost.HttpControllerHandler.EndProcessRequest(IAsyncResult result) +159
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
My controller has two functions;
- GetModels that returns a list of 'Model': this function has no parameters and runs fine.
- GetModelByName that should return a model by its name. Calling this function causes the error mentioned above.
The URL used for this function is: http://dnndev.me/DesktopModules/Certigo.Policy.CreateModule/API/model/byname
Below is the sourcecode of my controller.
[SupportedModules(Constants.DESKTOPMODULE_NAME)]
public class ModelController : DnnApiController
{
/// <summary>
/// API that returns an models list
/// </summary>
/// <returns></returns>
[HttpPost, HttpGet] //[baseURL]/model/list
[ValidateAntiForgeryToken]
[ActionName("list")]
[DnnModuleAuthorize(AccessLevel = SecurityAccessLevel.View)]
public HttpResponseMessage GetModels()
{
try
{
using (DialogServerClient client = new DialogServerClient())
{
DialogModelRequest request = new DialogModelRequest()
{
Domain = Constants.POLICY_DOMAIN,
Process = Constants.POLICY_PROCESS
};
return Request.CreateResponse(HttpStatusCode.OK, client.GetModels(request).DialogModels);
}
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
/// <summary>
/// API that returns a single model
/// </summary>
/// <returns></returns>
[HttpPost, HttpGet] //[baseURL]/model/byname
[ValidateAntiForgeryToken]
[ActionName("byname")]
[DnnModuleAuthorize(AccessLevel = SecurityAccessLevel.View)]
public HttpResponseMessage GetModel(RequestByName req)
{
try
{
using (DialogServerClient client = new DialogServerClient())
{
DialogModelRequest request = new DialogModelRequest()
{
Domain = Constants.POLICY_DOMAIN,
Process = Constants.POLICY_PROCESS,
Name = req.Name
};
return Request.CreateResponse(HttpStatusCode.OK, client.GetModel(request).DialogModels);
}
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
}
public class RequestByName
{
public string Name { get; set; }
}