在本地主机中访问HTTPS wcf服务 - CORS [英] Access HTTPS wcf service in local host - CORS
问题描述
大家好,
我正在尝试访问服务器上托管的WCF服务。该服务正在使用SSL连接。
我在IIS中分配了一个自签名证书。
该服务是一项全面的服务。
我试过两种不同的场景:
第一种情况:
我将网站托管到同一台服务器(访问服务的客户端应用程序)
在这种情况下,该服务是可访问的,并且能够从服务获得响应。
第二种情况:
我将网站托管到localhost,本地机器。
从这里,当我尝试向服务方法发出请求时,它无法访问。 :(
这是代码:
Hi All,
I am trying to access WCF service hosted on server. The service is using SSL connection.
I assigned a self signed certificate in IIS.
The service is a restfull service.
I tried with two different scenarios:
1st scenario :
I hosted the web site to same server(client application which access service)
In this case the service is accessible and able to get response from service.
2nd scenario :
I hosted the web site to localhost,local machine.
From here when I am trying to make request to service method it is not accessible. :(
Here is code :
function testHttps()
{
jsonText3=JSON.stringify({"Name":"Avinash"});
url="https://ServerIP/WcfSecureService/Service.svc/GetName";
var xhr = createCORSRequest('POST', url);
if (!xhr) {
alert('CORS not supported');
}
xhr.onload = function() {
alert(xhr.responseText);
};
xhr.onerror = function() {
alert('Woops, there was an error making the request.');
};
xhr.setRequestHeader('Content-Type', 'application/json') ;
xhr.send(jsonText3);
}
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
}
如何使用HTTPS使CORS呼叫成功?
我不想在客户端站点上安装任何证书。
如何通过Javascript验证服务?
请建议...
感谢您提前的帮助。
--Avinash
How to make CORS call success with HTTPS?
I do not want to install any certificate on client site.
How to authenticate service from Javascript?
Please suggest...
Thanks for your help in advance.
--Avinash
推荐答案
我的主要目标是通过移动浏览器上的HTTPS访问网站和Web服务。
在Android上:如果证书是自签名的,浏览器将首次要求接受证书。如果它是可信证书,它将在没有任何确认的情况下加载。
在iPhone / iPad上:不允许加载自签名证书。我们做了一个解决方法,使其工作。我禁用了证书检查并接受所有连接。
所以最后我能够通过HTTPS以分布式行为调用服务和网站。
谢谢,
Avinash
My main goal is to access the web site and web service through HTTPS on mobile browsers.
On Android : First time the browser will ask for accept certificate if certificate is self signed. If it is trusted certificate it will get loaded without any confirmation.
On iPhone/iPad : It is not allowing to load the self signed certificate. Se we did a workaround to make it work. I disabled certificate check and accept all connections.
So finally I am able to call service and web site from HTTPS with distributed behaviour.
Thanks,
Avinash
这篇关于在本地主机中访问HTTPS wcf服务 - CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!