Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 :
JavaScript
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;
}


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
Posted

1 solution

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
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900