【发布时间】:2016-05-23 20:02:11
【问题描述】:
我通过 ASP.NET MVC 4 创建了一个简单的 API:
public class ActionController : ApiController
{
[WebMethod]
public string getCommunities()
{
try
{
MethodClass method = new MethodClass();
return method.getCommunities();
}
catch(Exception ex)
{
return ex.Message.ToString();
}
}
}
正在尝试在 Method 类中调用此方法:
public string getCommunities()
{
return "bbb";
}
但无论出于何种原因,我都会收到此错误:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">cannot parse xml! Check file path</string>
我尝试用谷歌搜索该错误,但没有找到任何结果,以前有人见过这个错误吗?以及如何解决?
【问题讨论】:
-
WebMethod?为什么会在这里?
-
因为我打算通过 ajax 使用它
-
[WebMethod] 对于 MVC 应用程序不是必需的。页面方法是在 (aspx.cs) 页面后面的代码中执行的老式方法...
-
MethodClass构造函数中发生了什么?我怀疑这可能是Exception被抛出的地方...... -
@user979331 我注意到您对这个问题给予了赏金,但您收到的回复不太可能比您的回复更好。编辑问题以提供 GetCommunities() 的实现,您可能会得到答案!
标签: c# asp.net asp.net-mvc api