【发布时间】:2011-05-13 00:52:40
【问题描述】:
我的 Visual Studio 解决方案中有两个项目:MyApp.WebService 和 MyApp.WebUI。
我在 /Views/Home/Index.aspx 的 WebUI 项目中有一个视图页面,进行了这个 ajax 调用:
$.ajax({
type: "GET",
url: "MyService.svc/HelloWorld",
data: null,
processData: true,
contentType: "application/json",
dataType: "json",
cache: false,
success: function (data) {
alert(data.d);
}
});
我的 WebService 项目的根目录中有一个 .svc 文件,名为 MyService.svc,其中包含此函数:
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public string HelloWorld()
{
return "Hello, world!";
}
我收到一条错误消息,提示它找不到我正在调用的网址的位置。我怀疑这与另一个项目中的 .svc 文件有关。我需要做些什么来调用它吗?
【问题讨论】:
-
您可以在浏览器中导航到该网址或根 SVC 网址吗?