Reputation: 1664
I have a simple WCF service with the following interface:
[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>
<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:
$.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:
$.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. 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. What am I missing? What is the quickest/easiest way to get both these methods working?
Upvotes: 0
Views: 837
Reputation: 286
According to the code you posted, jscript calls the SavePages method but in the server side the post method has name SetPages.
Upvotes: 2