簡體   English   中英

如何為自托管WCF服務啟用跨域調用

[英]How to enable cross domain calls for self hosted WCF service

我創建了一個在Windows機器上運行的自托管WCF服務。 現在我想使用AJAX調用來使用服務的操作。 無論是在iExplorer,Firefox還是Chrome中,我都沒有得到應有的JSON流。

我必須添加到自托管服務才能允許跨域調用?

關心西蒙

http://pranayamr.blogspot.se/2011/06/calling-cross-domain-wcf-service-using.html似乎是一篇有效的文章。 您需要相應地配置服務。 這在過去對我有用。

對於托管在localhost \\ Service.mv​​c上的服務GetPerson,請使用:

$.ajax({
            type: 'GET', //GET or POST or PUT or DELETE verb
            url: 'Service.svc/GetPerson', // Location of the service
            data: userid, //Data sent to server
            contentType: 'application/json; charset=utf-8', // content type sent to server
            dataType: 'json', //Expected data format from server
            processdata: true, //True or False
            success: function (data) {//On Successfull service call
                alert(data.Name);
            },
            error: function (msg) {// When Service call fails
                alert(msg);
            }
        });

鏈接: http//www.cleancode.co.nz/blog/1041/complete-example-wcf-ajax-ssl-http

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM