【发布时间】:2016-10-12 23:55:59
【问题描述】:
我有一个 wcf 休息服务方法。 OperationContract 如下所示:
[OperationContract]
[WebGet(UriTemplate = "?maps/reporttypes/{reportType}/reportperiods/{reportPeriod}", ResponseFormat=WebMessageFormat.Json)]
Map GetData(int reportType, int reportPeriod);
我可以使用 WCF 测试客户端成功测试这个,所以我知道底层方法有效。但是,我在使用 $.ajax() 方法获取数据时遇到问题:
$.ajax({
url: 'http://localhost:52672/Service1.svc?maps/reporttypes/1/reportperiods/1',
success:function(data){
//bind data here
},
error:function(error){
}
});
上面的 ajax 方法返回成功,但如果您为服务选择“在浏览器中查看”,则数据值只是显示的页面的 html。知道我在这个实现中可能缺少什么吗?
【问题讨论】:
-
我认为网址中有错字。应该用斜杠代替问号:localhost:8080/service1.svc/reports/reportypes...
-
另外,请注意 UriTemplate 中还有一个错字。一个段是 reporttypes 而不是 reporttypes。但是由于它在两个地方都拼错了,所以应该没有太大关系;)
-
我更新了开发环境中的代码以及原始帖子中的代码。 url 返回成功,但仅返回默认服务视图的 html。我在这里错过了什么?
-
两者都在同一个端口上运行吗?如果提到了一些错误,你能看到 html 吗?
-
它们在不同的端口上运行。主网站在 localhost:8080 上运行,而服务在 localhost:52672 上运行。 html中没有错误。 html 只是反映了服务的通用 html 页面:jsbin.com/juwizokoje/edit?html,output