c# - Web Api 2 string response returns as an array of characters -
i have controller method:
[httpget] [route("systemcheck/pulsecheck")] public httpresponsemessage pulsecheck() { //this string var pulsecheck = pulsecheckhelper.pulsecheck(); var response = request.createresponse((httpstatuscode.ok), pulsecheck); return response; }
the response comes as: [ "2", "2", "9", "9" ] instead of "2299"
any ideas?
i have tried different variations like:
[httpget] [route("systemcheck/pulsecheck")] [responsetype(typeof(string))] public string pulsecheck() { //this string var pulsecheck = pulsecheckhelper.pulsecheck(); return pulsecheck; }
but same results. there webapiconfig i'm missing. have other applications work fine same controller method code haven't been able identify configuration differences.
this in webapiconfig:
public static void register(httpconfiguration config) { config.formatters.jsonformatter.serializersettings.preservereferenceshandling = preservereferenceshandling.objects; config.formatters.jsonformatter.serializersettings.referenceloophandling = referenceloophandling.serialize; config.formatters.jsonformatter.serializersettings.contractresolver = new camelcasepropertynamescontractresolver(); config.maphttpattributeroutes(); config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional } ); config.messagehandlers.add(new security.webapi.authenticationhandler()); config.services.getfilterproviders().tolist().foreach(provider => config.services.remove(typeof(system.web.http.filters.ifilterprovider), provider)); config.services.add(typeof(system.web.http.filters.ifilterprovider), new orderedfilterprovider()); config.filters.add(new exceptionhandlingattribute()); config.filters.add(new inspectactioncontextfilter()); config.filters.add(new newrelicfilter()); config.filters.add(new enablequeryattribute { pagesize = defaultpagesize, ensurestableordering = false }); }
update: seems culprit following code in webapiconfig register:
config.filters.add(new enablequeryattribute { pagesize = defaultpagesize, ensurestableordering = false });
this enabling odata queries controller methods. if remove lines right response "2299". question is, how can disable odata specific controller method?
looks treating string list of characters possibly query it. can force think single result changing action following:
[httpget] [route("systemcheck/pulsecheck")] public singleresult<string> pulsecheck() { var pulsecheck = pulsecheckhelper.pulsecheck(); return singleresult.create(new[]{ pulsecheck }.asqueryable()); }
Comments
Post a Comment