我创建了一个在Windows计算机上运行的自托管WCF服务。现在我想使用AJAX调用来使用服务的操作。无论是在iExplorer,Firefox还是Chrome浏览器中,我都会得到所需的JSON流。如何为自己托管的WCF服务启用跨域调用
为了允许跨域调用,我必须添加到自托管服务中?
问候 西蒙
我创建了一个在Windows计算机上运行的自托管WCF服务。现在我想使用AJAX调用来使用服务的操作。无论是在iExplorer,Firefox还是Chrome浏览器中,我都会得到所需的JSON流。如何为自己托管的WCF服务启用跨域调用
为了允许跨域调用,我必须添加到自托管服务中?
问候 西蒙
对于服务GetPerson托管在localhost \ Service.mvc使用:
$.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
http://pranayamr.blogspot.se/2011/06/calling-cross-domain-wcf-service-using.html似乎是一个有效的文章。您需要相应地配置您的服务。这在过去对我有用。
你用什么约束力? WCF服务如何托管(进程?IIS?) –
webHttpBinding,并且它作为服务托管在Windows中,使用ServiceBase.Run(new ioNotificationService()); – Simon