내가 만든 WCF 서비스 응용 프로그램에서 JSON 데이터를 가져 오는 데 문제가 발생했습니다. 내가 jQuery를 사용하여 웹 응용 프로그램에서이 데이터에 액세스하려고WCF에서 JQuery를 통해 JSONP에 액세스
[{"RoomId":1,"RoomName":"Big Room"},{"RoomId":2,"RoomName":"Medium Room"},{"RoomId":3,"RoomName":"Small Room"}]
: 나는 다음과 같은 JSON을 반환하는 간단한 WCF 서비스가 있습니다. 데이터를 시도하고 검색하기 위해 다양한 JQuery 문을 시도했지만 아무것도 표시되지 않습니다.
이$(function() {
$.getJSON('http://localhost:6188/RoomBookingService.svc/GetRooms?callback=Rooms', function (data) {
alert(data);
});
는 IS 다음 내 WCF 서비스 응용 프로그램 코드 :
[ServiceContract]
public interface IRoomBookingService
{
[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare,ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetRooms")]
Room[] GetRooms();
구성은 :
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="RoomBookingServices.RoomBookingService" behaviorConfiguration="RoomBookingServiceBehaviour">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="RoomBookingServices.IRoomBookingService" behaviorConfiguration="webHttpBehavior">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="RoomBookingServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- 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 -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />-->
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
나는 JQuery와이 할 필요가 돌려 주어 다음은 내 가장 최근의 시도이다 JSON을 나중에 div 태그로 표시하거나 나중에 형식을 지정합니다. 어떤 도움이라도 좋을 것입니다.
미리 감사드립니다.
브라우저 창에 입력 http : // localhost : 6188/RoomBookingService.svc/GetRooms? callback = 객실 및 결과보기 – Luke
여기서 어떤 문제가 발생합니까? – mowwwalker