use*_*331 4 c# asp.net api asp.net-mvc
我通过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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
试图在Method类中调用此方法:
public string getCommunities()
{
return "bbb";
}
Run Code Online (Sandbox Code Playgroud)
但无论出于何种原因,我都会收到此错误:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">cannot parse xml! Check file path</string>
Run Code Online (Sandbox Code Playgroud)
我尝试使用谷歌搜索错误,但没有提出任何问题,有没有人见过这个错误?以及如何解决?
正如评论中已经指出的那样,您正在错误的地方寻找您的错误.method.getCommunities()抛出错误消息"无法解析xml!检查文件路径".
谷歌搜索你的错误在我看来你抛出一个自定义异常:在你的代码中搜索该字符串可能会指向正确的位置.
作为概念的快速证明,我更改了Visual Studio Web API模板生成的标准API.
public string Get(int id)
{
try
{
var t = 0;
var i = 1 / t;
return "bbb";
}
catch { return "ABBA"; }
}
Run Code Online (Sandbox Code Playgroud)
它将自定义错误消息准确地返回为xml字符串
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">ABBA</string>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
282 次 |
| 最近记录: |