在ASMX中编写了一种Web方法,以将JSON数据返回到Angular应用程序。因此,这是Webmethod的外观]
[WebMethod]
[ScriptMethod(UseHttpGet =true,ResponseFormat =ResponseFormat.Json)]
public MyProjects getReport(int reportId)
{
}
这是我从Angular调用它的方式
this.client.get('http://localhost:51071/webservice1.asmx/getReport?reportId=596',
{ withCredentials: true, responseType: 'text' })
.subscribe( (data) => console.log(data));
但是问题是在angular app处接收的数据为XML格式。那就是我在那里指定文本的原因。如果我在那里指定json,则当然会触发错误消息,指出无效的json数据。
我完全不知道我做错了什么或更改了什么才能获得纯JSON
这是控制台输出的样子
<?xml version="1.0" encoding="utf-8"?>
<Projects xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Success>true</Success>
<TotalRecords>391</TotalRecords>
<Data>
<ProjectData>
<ProjectCode>E6012</ProjectCode>
您确定您的IIS配置吗?