开发者

WCF - JSONP Content-Length Issue

Scenario:

Web Service needed to calculate values and send results back as json. These calls are to be made cross-domain so I'm using jsonp. The problem I'm having occurs both on the same domain and cross-domain.

Problem:

I'm having an issue getting back json data from a WCF Service. While on my local machine it works fine, but when on the server the response from the service is cut short (if I run it through Visual Studio on the server though, it's fine).

The content length seems to be set as the length of my response before wrapping it in the jquery callback function (example data below).

Local: jQuery151017220264650085249_1309423933796({"d":"[\"Flat\",\"Terrace\",\"Semi\",\"Detached\",\"Bungalow\"]"});

Local: jQuery151017220264650085249_1309423933797({"d":"[\"New build\",\"2000 to 2010\",\"1990 to 2000\",\"1970 to 1990\",\"1950 to 1970\",\"Pre 1950\"]"});

Live: jQuery1510246237260361726_1309424024004({"d":"[\"Flat\",\"Terrace

Live: jQuery1510246237260361726_1309424024005({"d":"[\"New build\",\"2000 to 2010\",\"1990 to 2000\",\"1970 to

To wrap the json response with the callback function I had to use a httpmodule I found on the net.

The server uses IIS 7.5, locally i'm just using Visual Studio. (Some kind of IIS configuration?)

Right, hopefully I'开发者_开发技巧ve provided enough information, if not let me know.

So if anyone has any idea how I could fix this issue it would be greatly appreciated.

Thanks


You don't need to use an HTTP Module to wrap the response in JSONP - this feature is available in WCF 4.0. You can set the property CrossDomainScriptAccessEnabled in WebHttpBinding, and if the request comes from a different domain (and it has a ?callback=FunctionName) parameter, the response will be wrapped in FunctionName(...).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜