Hi
Facts first
1) Have hosted a Restful WCF Service on IIS 7.0 on localhost and exposed two methods one using GET and the other POST.
2) My client would be a HTML page that would use JQUERY/AJAX to invoke the WCF service.
3) the Get Methods are returning JSON and the post method is posting JSON data
4) Did everything shown in the link http://www.topwcftutorials.net/2014/02/Post-JSON-to-WCF-RESTful-Service.html
The Get method works but the POST methods keep throwing HTTP 405 Errors. I could see the same in Fiddler.
I am really getting frustrated since there is no solution since 72 hrs
Source Code below
Thanks.
Rajaraman.S
IOrderService
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/PlaceSingleOrder")]
bool PlaceSingleOrder(string orderId);
OrderService.svc
public bool PlaceSingleOrder(string orderId)
{
try
{
return true;
}
catch (Exception ex)
{
throw new FaultException<string>
(ex.Message);
}
return true;
}
web.config ( WCF Service)
<service behaviorConfiguration="Default" name="RestfulWcfServiceOnIIS.OrderService">
<endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding" contract="RestfulWcfServiceOnIIS.IOrderService" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
......
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
---
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept"/>
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS"/>
<add name="Access-Control-Max-Age" value="1728000"/>
</customHeaders>
</httpProtocol>
---WcfClient.html file ( client)
$("#btnPlaceSingleOrder").click(function () {
alert('Place Single Orders...');
$.ajax({
type: "POST",
url: "http://localhost:8080/OrderService.svc/PlaceSingleOrder",
data: "{OrderID:'25'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
crossdomain: true,
processData: true,
success: function (data, status, jqXHR) {
alert("success..." + data);
},
error: function (xhr) {
alert(xhr.responseText);
}
});
});
No configurations in the the client html page