0

Hi Everyone,

I am trying to use Ajax to submit an XML Web Service request and receive a response XML. While it works perfectly when I submit these requests directly from the XXXX, YYYY, ZZZZ servers on the intranet. The request gets stuck at .open if I connect from any other server ABCD. However, if I use the url(asmx) to check the connection from a browser on ABCD, I am able to see the list of available web method and the corresponding wsdl file. Not sure why its not letting me submit requests through AJAX.

Apologies if my language is very amateurish as I am not much aware of this stuff. I am not even using localhost or anything in the url.

Please help. I have attached the full HTML file for reference.

Thanks in advance.

Best Regards,

Sriram

var url = document.getElementById("GWSInstance").getAttribute("value");
var mthd = document.getElementById("WebMethod").getAttribute("value");
//Set target node
objXMLHttpRequest.open("POST", url, true);
objXMLHttpRequest.setRequestHeader("Content-Type", "text/xml");

//Set web method to consume
objXMLHttpRequest.setRequestHeader("SOAPAction",mthd);

The corresponding <select> elements in the HTML file are as follows:

<label>Instance:</label>
<select id = 'GWSInstance'>
<option value = 'http://XXXX/GwsIS/IntegrationService.asmx'>http://XXXX/GwsIS/IntegrationService.asmx</option>
<option value = 'http://YYYY/GwsIS138002320/IntegrationService.asmx'>http://YYYY/GwsIS138002320/IntegrationService.asmx</option>
<option value = 'http://ZZZZ/GwsIS/IntegrationService.asmx'>http://ZZZZ/GwsIS/IntegrationService.asmx</option>
</select>
<label>Web Method:</label>
<select id = 'WebMethod'>
<option value = 'http://rebusis.com/webservices/gcs/IntegrationService/ProcessNA'>ProcessNA</option>
<option value = 'http://rebusis.com/webservices/gcs/IntegrationService/ProcessUW'>ProcessUW</option>
<option value = 'http://rebusis.com/webservices/gcs/IntegrationService/ProcessClaim'>ProcessClaim</option>
<option value = 'http://rebusis.com/webservices/gcs/IntegrationService/ProcessAccounts'>ProcessAccounts</option>
</select>
Attachments
<html>
<head>
<script type='text/javascript'>


function displaymessage()
{
alert("Hello World!");
}


function CreateXMLHttpRequest() {
        if (typeof XMLHttpRequest != "undefined"){
            
            return new XMLHttpRequest();
        }
        else if (typeof ActiveXObject != "undefined") {
            //For IE 5 & 6
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
        else {
            throw new Error("Browser does not support XMLHttpRequest");
        }
    }


function getSOAPResponse()
{

var temp = document.getElementById('ReqFile').value.lastIndexOf('.');
var objXMLHttpRequest = CreateXMLHttpRequest();
var objXMLHttpRequest2 = CreateXMLHttpRequest();
var reqPath = document.getElementById("ReqFile").value;
var extn = reqPath.substring(temp + 1, reqPath.length);
if(extn != "xml")
{
alert("Please select a request XML file.");
return;
}


document.getElementById("status").src = "processing.gif";
document.getElementById("animation").style.visibility = "visible";
document.getElementById("rqst").src = reqPath;

//Create XMLHTTPRequest on local folder to fetch request.xml file
var setTime = setTimeout("ajaxTimeout();",30000);
objXMLHttpRequest2.open("GET", reqPath, false);
        var packet = null; 
        objXMLHttpRequest2.onreadystatechange = function() { 
                if(objXMLHttpRequest2.readyState == 4)  {
                        packet=objXMLHttpRequest2.responseText;
                } 
        } 
        objXMLHttpRequest2.send(null);  

//Create XMLHTTPRequest on remote GWS Server		
var url = document.getElementById("GWSInstance").getAttribute("value");
var mthd = document.getElementById("WebMethod").getAttribute("value");
//Set target node
objXMLHttpRequest.open("POST", url, true);
objXMLHttpRequest.setRequestHeader("Content-Type", "text/xml");

//Set web method to consume
objXMLHttpRequest.setRequestHeader("SOAPAction",mthd);


objXMLHttpRequest.onreadystatechange = function(){
clearTimeout(setTime);
       if (objXMLHttpRequest.responseText) {

			
			//On successful response, write response XML message to response.xml file.
            		result= objXMLHttpRequest.responseText;
			var respMsg = new ActiveXObject("Scripting.FileSystemObject");
			var index = 0;
			reqPath = reqPath.substring(0,reqPath.lastIndexOf('.'));
			while (respMsg.FileExists(reqPath + "-resp-" + index + ".xml"))
			{
			index = index + 1;
			}
			var respXML = respMsg.CreateTextFile(reqPath + "-resp-" + index + ".xml", true); //Overwrite = true
			respXML.WriteLine(result);
			respXML.Close();
			
			setTimeout(document.getElementById("resp").src = reqPath + "-resp-" + index + ".xml",2000);
			document.getElementById("status").src = "success.png";
        }
		else {
		document.getElementById("status").src = "error.jpg";
		}
		

}
objXMLHttpRequest.send(packet);

}
function ajaxTimeout() {
alert("Request timed out.");

}

</script>
</head>

<body>
<form>
<!-- Select Target Node -->
<label>Instance:</label>
<select id = 'GWSInstance'>
<option value = 'http://XXXX/GwsIS/IntegrationService.asmx'>http://XXXX/GwsIS/IntegrationService.asmx</option>
<option value = 'http://YYYY/GwsIS138002320/IntegrationService.asmx'>http://YYYY/GwsIS138002320/IntegrationService.asmx</option>
<option value = 'http://ZZZZ/GwsIS/IntegrationService.asmx'>http://ZZZZ/GwsIS/IntegrationService.asmx</option>
</select>
<label>Web Method:</label>
<select id = 'WebMethod'>
<option value = 'http://rebusis.com/webservices/gcs/IntegrationService/ProcessNA'>ProcessNA</option>
<option value = 'http://rebusis.com/webservices/gcs/IntegrationService/ProcessUW'>ProcessUW</option>
<option value = 'http://rebusis.com/webservices/gcs/IntegrationService/ProcessClaim'>ProcessClaim</option>
<option value = 'http://rebusis.com/webservices/gcs/IntegrationService/ProcessAccounts'>ProcessAccounts</option>
</select>
<input type='button' value='Get SOAP response' onclick='getSOAPResponse()' ></input><br/>
<input type='file' id="ReqFile"></input>
<br/>
<div id='animation' valign = 'middle' style = 'visibility:hidden; text-align:center; z-index:100000; position:relative'><img width='28px' height='28px'  id='status' src='processing.gif'></img></div>
</form>
<div id='frms' valign = 'middle' style = 'text-align:center; z-index:20; position:relative'>
<table border=1 width='100%' height='1000'>
<tr>
<td width='50%'><iframe id='rqst' width='100%' style='z-index:10' height='100%'></iframe>
<td width='50%'><iframe id='resp' width='100%' style='z-index:10' height='100%'></iframe>
</tr>
</table>
</div>
<br/>

</body>
</html>
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by digital-ether
1

Are you aware that XMLHTTPRequest can only be made to the same domain?

You need the domain you're requesting from to grant cross domain access somehow or you will have to proxy the request.

0

Yes, I agree that it can't be a cross-domain request. However, I had enabled Miscellaneous -> Access Data Sources across domains... in the IE security setup. I happened to understand that once that is enabled, you can actually submit cross-domain request through Ajax. Please correct me if I am wrong.

Thanks for your help.

0

From the docs it seems it should work.

Try taking a look at the HTTP request with a tool like Wireshark so see if you're actually getting a HTTP request.

Also if you use a try/catch block around the xmlhttprequest open method you should see the error mesage.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.