WCF RIA Services에는 JSON을 사용하는 데 사용할 수있는 Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory가 있다는 것을 알고 있습니다. JSONP를 통해 도메인 간 호출을 사용하도록 설정해야합니다. 이 작업을 수행 할 기존 DomainServiceEndpointFactory가 있습니까?WCF Ria Services의 JSONP endpoing을 추가하여 도메인 간 호출을 활성화하려면 어떻게해야합니까?
1
A
답변
1
JasonEndpointFactory를 오버로드하고 거기에 바인딩을 적용한 다음 새 클래스를 사용하여 끝점을 추가했습니다.
namespace Bodge
{
public class JsonPEndpointFactory : JsonEndpointFactory
{
public override IEnumerable<ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost)
{
IEnumerable<ServiceEndpoint> endPoints = base.CreateEndpoints(description, serviceHost);
foreach (ServiceEndpoint endPoint in endPoints)
{
if (endPoint.Binding is WebHttpBinding)
{
((WebHttpBinding)endPoint.Binding).CrossDomainScriptAccessEnabled = true;
}
}
return endPoints;
}
}
}
<endpoints>
<add name="JSONP" type="Bodge.JsonPEndpointFactory, Bodge, Version=1.0.0.0"/>
</endpoints>
그런 다음 엔드 포인트와 콜백 쿼리 매개 변수로 서비스에 액세스하십시오. http://blah/service.svc/JSONP/GetStuff?callback=callbackname
희망 하시다면, 크리스.
+0
대단히 고마워요, 제가 정확히 찾고있는 것이에요. – JJS
1
주석의 서식 지정은 좋지 않으므로 나중에 나중에 사용하기 위해 필요한 사용법과 어셈블리를 참조하십시오.
네임 스페이스 :
using System.Web;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
using Microsoft.ServiceModel.DomainServices.Hosting;
어셈블리
으로 netfx 4.0
이System.ServiceModel
System.ServiceModel.Web
!
정말 감사합니다, 그게 내가 나중에 참조 할 수 있도록, 이들이 사용하는 문장입니다 필요한 것을 정확히
System.ServiceModel.DomainServices.Hosting
System.ServiceModel.DomainServices.Server
WCF RIA Services Toolkit (September 2011)
Microsoft.ServiceModel.DomainServices.Hosting
으로 WebHttpBinding의 crossDomainScriptAccessEnabled 속성을 사용할 필요가 것입니다. EndPointFactory가 서비스 인스턴스를 생성 할 때이 동작을 수행하는 방법이 있습니까? – JJS