【发布时间】:2016-03-28 19:15:36
【问题描述】:
我在我的 asp.net web api 应用程序中使用 .asmx 服务,如下所示:
[
但是这个服务什么也不返回,而是在 HTTP 响应对象中写入响应,如下所示: ` [WebMethod(EnableSession = true)] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] 公共无效GetResearchDocsBySector(int pageCode,int resultsPerPage,字符串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));
}`
我想在我的 webapi 应用程序中以 json 格式使用从服务获得的结果,我们该怎么做?
注意:我根本无法更改 .asmx 服务代码!!
【问题讨论】:
-
请勿将代码发布为图片。我们不使用图片进行编程。图片使在答案中重新利用您的代码变得困难,它们无法编辑,也无法搜索。请编辑您的问题以更正此问题。
标签: c# asp.net web-services wcf asp.net-web-api