rosh_021 rosh_021 - 1 year ago 74
Ajax Question

calling wcf service from jquery ajax - getting exception - incoming request is not allowed

Exception details:

A first chance exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.Web.dll
Additional information: The HTTP method 'GET' of the incoming request (with URI http://localhost:24342/Test.svc/DoWork?callback=jQuery110203769165082986856_1479380612393&testParameter=TEST&_=1479380612394) is not allowed.

I am using Ajax-embedded WCF service. WCF client is a jQuery Ajax call. My code:

[ServiceContract(Namespace = "testWCFAjax")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service
[System.ServiceModel.Web.WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json )]
public string DoWork(string testParameter)
return "success";

Web Config:

<behavior name="ServiceAspNetAjaxBehavior">
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<service name="Service">
<endpoint address="" behaviorConfiguration="ServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="Service"/>

Ajax Code:

<script src="Scripts/jquery-1.9.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function CallMyService() {
$.support.cors = true;
var param = '{"testParameter": "TEST"}';
url: 'http://localhost:24342/Test.svc/DoWork',
data: param,
type: "POST",
dataType: "jsonp",
contentType: "application/json",
success: ServiceSucceeded,
error: ServiceFailed

Answer Source

I was able to solve this issue by creating WCF service with Ajax-embedded.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download