Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing JSONP from WCF via JQuery
    primarykey
    data
    text
    <p>I have been having some issues retrieving JSON data from a WCF service application I have created. I have a simple WCF service which returns the following JSON:</p> <pre><code>[{"RoomId":1,"RoomName":"Big Room"},{"RoomId":2,"RoomName":"Medium Room"},{"RoomId":3,"RoomName":"Small Room"}] </code></pre> <p>I am trying to access this data from a web application using JQuery. I have tried various JQuery statements to try and retrieve the data but nothing appears. The following is my most current attempt:</p> <pre><code>$(function () { $.getJSON('http://localhost:6188/RoomBookingService.svc/GetRooms?callback=Rooms', function (data) { alert(data); }); </code></pre> <p>The following is my WCF service application code:</p> <pre><code>[ServiceContract] public interface IRoomBookingService { [OperationContract] [WebGet(BodyStyle = WebMessageBodyStyle.Bare,ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetRooms")] Room[] GetRooms(); </code></pre> <p>Config:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;configuration&gt; &lt;system.web&gt; &lt;compilation debug="true" targetFramework="4.0" /&gt; &lt;/system.web&gt; &lt;system.serviceModel&gt; &lt;services&gt; &lt;service name="RoomBookingServices.RoomBookingService" behaviorConfiguration="RoomBookingServiceBehaviour"&gt; &lt;endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="RoomBookingServices.IRoomBookingService" behaviorConfiguration="webHttpBehavior"&gt; &lt;/endpoint&gt; &lt;/service&gt; &lt;/services&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="RoomBookingServiceBehaviour"&gt; &lt;!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --&gt; &lt;serviceMetadata httpGetEnabled="true"/&gt; &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --&gt; &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;endpointBehaviors&gt; &lt;behavior name="webHttpBehavior"&gt; &lt;webHttp/&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; &lt;/behaviors&gt; &lt;bindings&gt; &lt;webHttpBinding&gt; &lt;binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" /&gt; &lt;/webHttpBinding&gt; &lt;/bindings&gt; &lt;!--&lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt;--&gt; &lt;/system.serviceModel&gt; &lt;system.webServer&gt; &lt;modules runAllManagedModulesForAllRequests="true"/&gt; &lt;/system.webServer&gt; &lt;/configuration&gt; </code></pre> <p>All I need the JQuery to do is return the JSON and display it in a div tag or something, as later it will be formatted. Any help would be great.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload