[英]How to enable cross domain calls for self hosted WCF service
I created a self hosted WCF service which runs on a windows machine. 我创建了一个在Windows机器上运行的自托管WCF服务。 Now I would like to consume the service's operations using AJAX calls.
现在我想使用AJAX调用来使用服务的操作。 Neither in iExplorer, Firefox nor Chrome I get a resulting JSON stream as supposed to.
无论是在iExplorer,Firefox还是Chrome中,我都没有得到应有的JSON流。
What do I have to add to the self hosted service in order to allow cross domain calls? 我必须添加到自托管服务才能允许跨域调用?
Regards Simon 关心西蒙
http://pranayamr.blogspot.se/2011/06/calling-cross-domain-wcf-service-using.html Seems like a valid article. http://pranayamr.blogspot.se/2011/06/calling-cross-domain-wcf-service-using.html似乎是一篇有效的文章。 You need to configure your service accordingly.
您需要相应地配置服务。 This has worked for me in the past.
这在过去对我有用。
You have to add extra methods to expose cross domain policies, 您必须添加额外的方法来公开跨域策略,
http://blogs.msdn.com/b/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx http://blogs.msdn.com/b/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx
For Service GetPerson hosted on localhost\\Service.mvc use: 对于托管在localhost \\ Service.mvc上的服务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);
}
});
Link: http://www.cleancode.co.nz/blog/1041/complete-example-wcf-ajax-ssl-http 链接: http : //www.cleancode.co.nz/blog/1041/complete-example-wcf-ajax-ssl-http
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.