[英]WCF JSON service with 2 methods called via jquery. GET method works, POST method returns 404 error
I have a simple WCF service with the following interface: 我有一个简单的WCF服务,具有以下接口:
[ServiceContract]
public interface IPageService {
[OperationContract]
[WebGet(UriTemplate = "/GetPage/{pageNumber}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Page GetPage(string pageNumber);
[OperationContract]
[WebInvoke(UriTemplate = "/SetPages", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
string SetPages(Page[] pages);
}
The system.serviceModel section of the config file is as follows: 配置文件的system.serviceModel部分如下:
<system.serviceModel>
<protocolMapping>
<add scheme="http" binding="webHttpBinding"/>
</protocolMapping>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior>
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Using the following JavaScript to call the GetPage method works: 使用以下JavaScript调用GetPage方法有效:
$.ajax({
cache: false,
url: 'http://localhost/Test/PageService.svc/GetPage/1',
type: 'GET',
success: function(result) {
// do success stuff
},
error: function(req, status, error) {
// do error stuff
}
});
Using the following JavaScript to call the SetPages method returns a 404 error: 使用以下JavaScript调用SetPages方法会返回404错误:
$.ajax({
cache: false,
url: 'http://localhost/Test/PageService.svc/SavePages',
type: 'POST',
data: '[{...}]',
dateType: 'json',
contentType: 'application/json',
processData: false,
success: function(result) {
// do success stuff
},
error: function(req, status, error) {
// do error stuff
}
});
I've tried almost every combination of parameters in the ajax call already and nothing makes a difference. 我已经在ajax调用中尝试了几乎所有参数组合,没有任何区别。 I've played around with the config file and tried various configurations suggested here and in various blogs but all that does is make both methods return AddressFilter or ContractFilter mismatches.
我已经玩过配置文件并尝试了各种配置和各种博客,但所有这些都使得两种方法都返回AddressFilter或ContractFilter不匹配。 What am I missing?
我错过了什么? What is the quickest/easiest way to get both these methods working?
让这两种方法都起作用的最快捷/最简单的方法是什么?
根据您发布的代码,jscript调用SavePages方法,但在服务器端,post方法具有名称SetPages。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.