Cannot complete a JSONP call from jQuery to WCF
Posted
by Dusda
on Stack Overflow
See other posts from Stack Overflow
or by Dusda
Published on 2009-07-21T20:30:19Z
Indexed on
2010/04/08
13:53 UTC
Read the original article
Hit count: 388
Okay, I am trying (poorly) to successfully make a JSONP call from jQuery on a test page to a WCF web service running locally, as a cross-domain call. I have, at one point or another, either gotten a 1012 URI denied error, gotten a response but in Xml, or just had no response at all. Currently, the way I have it configured it spits back a 1012.
I did not write this web service, so it is entirely possible that I am just missing a configuration setting somewhere, but I've become so frustrated with it that I think just asking on here will be more productive. Thanks guys. Details below.
I have a WCF web service with the following method:
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public decimal GetOrderStatusJson(int jobId)
I am trying to call this method from a jQuery test page, via a cross-domain JSONP call.
<script type="text/javascript">
getJsonAjaxObject(
"http://localhost:3960/ProcessRequests.svc/json/GetOrderStatusJson",
{ "jobId": 232 });
function getJsonAjaxObject(webServiceUrl, jsonData) {
var request = {
type: "POST",
contentType: "application/json; charset=utf-8",
url: webServiceUrl,
data: jsonData,
dataType: "jsonp",
success: function(msg) {
//success!
alert("blah");
},
error: function() {
//oh nos
alert("bad blah");
}
};
$.ajax(request);
}
</script>
Below are the chunks of the web.config I configure for this purpose:
<services>
<service behaviorConfiguration="MWProcessRequestWCF.ProcessRequestsBehavior"
name="MWProcessRequestWCF.ProcessRequests">
<endpoint address="json" behaviorConfiguration="AspNetAjaxBehavior"
binding="webHttpBinding" contract="MWProcessRequestWCF.IProcessRequests" />
<endpoint address="" binding="wsHttpBinding" contract="MWProcessRequestWCF.IProcessRequests">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MWProcessRequestWCF.ProcessRequestsBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="AspNetAjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
© Stack Overflow or respective owner