我知道WCF RIA Services有一個Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory,可以用來啓用JSON。 我需要通過JSONP啓用跨域調用。是否有一個現有的DomainServiceEndpointFactory可以實現這一點?如何爲WCF Ria服務添加JSONP端點以啓用跨域呼叫?
1
A
回答
1
我只需要做到這一點 - 我重寫了JsonEndpointFactory,並用那裏的綁定修飾,然後使用新類添加了一個端點。
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 2012-01-26 17:46:11
1
註釋的格式不是很好,所以爲了將來的參考,這裏是所需的使用和裝配。
非常感謝,這正是我所需要的供以後參考,這些都是using語句:
命名空間:
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
相關問題
- 1. 如何配置通過跨域AJAX呼叫的WCF服務
- 2. 通過跨域JSONP AJAX呼叫通過WCF服務檢索HTML字符串
- 3. 404 WCF RIA服務端點
- 4. WCF RIA服務域服務
- 5. 如何加載WCF Ria Ria服務/ Linq2SQLDomainModel
- 6. WCF RIA域名服務
- 7. 拆卸WCF服務呼叫
- 8. 添加模型到Silverlight WCF RIA服務啓用應用程序
- 9. WCF RIA服務域服務元數據
- 10. 確保跨域呼叫
- 11. 如何爲現有的WCF服務本地啓用JSONP?
- 12. 如何從Silverlight進行跨域呼叫?
- 13. 無法呼叫我的wcf端點
- 14. WCF RIA通用服務器端查詢?
- 15. WCF RIA服務
- 16. 如何添加端點行爲以打開IIS託管的WCF服務
- 17. WCF RIA服務,加入域服務中的表
- 18. 如何從異步RIA服務呼叫接收通知?
- 19. Biztalk發送端口呼叫.asmx服務
- 20. WCF/WCF數據服務/ WCF RIA服務
- 21. 使用New Relic跨越服務器/服務邊界的呼叫
- 22. 呼叫服務
- 23. 直接呼叫WCF服務主機
- 24. WCF服務 - 呼叫重定向問題
- 25. WCF服務呼叫期間後
- 26. 呼叫託管的WCF服務從PHP
- 27. .NET RIA服務/ WCF服務
- 28. 添加新行以在Silverlight WCF RIA服務
- 29. 如何使用HTTPWebRequest或Webclient呼叫休息WCF服務?
- 30. WCF服務(與RIA)
的的WebHttpBinding的crossDomainScriptAccessEnabled屬性是需要啓用的。當EndPointFactory創建服務實例時,是否有一種方法可以處理這種情況? – JJS 2012-01-13 04:34:49