Reputation: 11
I am consuming the .asmx service in my asp.net web api application like this :
[
but this service returns nothing, but in turn writes response in HTTP response object like this: ` [WebMethod(EnableSession = true)] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void GetResearchDocsBySector(int pageCode, int resultsPerPage, string subTypeIds, int timeframe) { JavaScriptSerializer js = new JavaScriptSerializer(); IRatingsDirectDataMgr dataMgr = RemoteUtil.GetRemote();
List<ResearchDocumentDisplay> results = dataMgr.GetSolrResults(pageCode, resultsPerPage, subTypeIds, timeframe, false);
List<ResearchDocumentWidgetDisplay> resultList = new List<ResearchDocumentWidgetDisplay>();
foreach (var item in results)
{
var obj = ObjMapper<ResearchDocumentDisplay, ResearchDocumentWidgetDisplay>.Map(item);
obj.ArticleTypeName = Constants.TypeMappings[obj.ArticleTypeId];
resultList.Add(obj);
}
HttpContext.Current.Response.Write(js.Serialize(resultList));
}`
I want to consume the result obtained from the service in my webapi application in json format how can we go about it ?
Note : I can't change the .asmx service code at all !!
Upvotes: 1
Views: 900
Reputation: 182
Set GetResearchDocsBySector to return your List rather than having a void return type and injecting it into the Current http content. TO do this you will need to mark ResearchDocumentWidgetDisplay as Serialisable which you do by adding [Serialisable] above your class ResearchDocumentWidgetDisplay.
Upvotes: 1