[英]WCF javascript proxy cross domain prevent access database
So I just follow this tutorial to implement a wcf service : http://www.codeproject.com/Articles/627082/How-to-Consume-WCF-Service-using-JavaScript-Proxy . 因此,我只是按照本教程来实现wcf服务: http : //www.codeproject.com/Articles/627082/How-to-Consume-WCF-Service-using-JavaScript-Proxy 。
In summary: 综上所述:
So my question is: Is this the normal architecture for this kind of WCF service (Generating js proxy to expose service to javascript clients). 所以我的问题是:这是这种WCF服务的常规体系结构(生成js代理以将服务公开给javascript客户端)。 I write this WCF to expose the service to mobile devices.
我编写此WCF是为了将服务公开给移动设备。 And if yes, is the CORS that preventing me from accessing the database when calling the service from client javascript?
如果是的话,是从客户javascript调用服务时,CORS是否阻止我访问数据库?
Try this way 试试这个
$.ajax({
url:'<ip address/site name>/wcfService.svc/method1',
contentType: "application/json; charset=UTF-8",
crossDomain: true,
dataType:'json',
data:{a:'<parameter value being sent>'}, //pass any parameter that are expected by the remote WCF service method(method1).
success:function(response) {
//Process the data(json/ normal data) retrieved from remote service.
}
});
Note:Enable Access-Control-Allow-Origin
option on the remote server end for make it CORS
compatible. 注意:在远程服务器端上启用
Access-Control-Allow-Origin
选项,以使其与CORS
兼容。 Best way to do this would be to configure this under behavior level itself, instead of service contract
or operation contract
level.ref:blogs.microsoft.co.il/idof/2011/07/02/ 最好的方法是在行为级别本身而不是
service contract
或operation contract
级别下进行配置。ref:blogs.microsoft.co.il/idof/2011/07/02/
Happy Coding:) 快乐编码:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.