[英]Consuming .asmx service in asp.net web api application
I am consuming the .asmx service in my asp.net web api application like this : 我在asp.net网络api应用程序中使用了.asmx服务,如下所示:
[ [
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(); 但此服务未返回任何内容,而是依次将响应写在HTTP响应对象中: ,string subTypeIds,int timeframe){JavaScriptSerializer js = new JavaScriptSerializer(); IRatingsDirectDataMgr dataMgr = RemoteUtil.GetRemote();
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 ? 我想以json格式使用从我的webapi应用程序中的服务获得的结果,如何处理?
Note : I can't change the .asmx service code at all !! 注意:我根本无法更改.asmx服务代码!
Set GetResearchDocsBySector to return your List rather than having a void return type and injecting it into the Current http content. 将GetResearchDocsBySector设置为返回您的列表,而不是使用无效的返回类型并将其注入到当前http内容中。 TO do this you will need to mark ResearchDocumentWidgetDisplay as Serialisable which you do by adding [Serialisable] above your class ResearchDocumentWidgetDisplay.
为此,您需要通过在类ResearchDocumentWidgetDisplay上方添加[Serialisable],将ResearchDocumentWidgetDisplay标记为Serialisable。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.