Connecting Tech Pros Worldwide Forums | Help | Site Map

XMLHttpRequest problem with Firefox and Netscape

Newbie
 
Join Date: Jan 2007
Posts: 1
#1: Jan 8 '07
Hi Guys,

I have a security concern with Mozilla and Netscape browsers(In IE it gives secuirity pop window) in Remote server(Client's server).When I am trying to call an Asp.NET web service from javascript using the XmlHttpRequest object

XmlHttpRequest .Open("POST", ServicesPath, false);

Problem is only in Cleint's server ,Where in web Service path given in Webconfig file is server name(not the Ip Address, We noticed that Client is using same IP number with diffrent Port number to access the diffrent application. I.e The server IP number and a port also used to access this application). I think it works fine, if we mention webservice path as IP Number with the correct PORT number. which combination is used to access the application. But we cannot modify the Host file in Client machine.

It works beautifully! in local server , where we are modifying the local host file by regestering the IP number with name, and using name in webconfig file to give service path.

CODE SNIPPET :

function createXMLHttp(sxml)
{
if (typeof XMLHttpRequest != "undefined") {
return new XMLHttpRequest();
}
else if (window.ActiveXObject) {
var aVersions = [ "MSXML2.XMLHttp.5.0",
"MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
"MSXML2.XMLHttp","Microsoft.XMLHttp"];

for (var i = 0; i < aVersions.length; i++) {
try {
var oXmlHttp = new ActiveXObject(aVersions[i]);
return oXmlHttp;
}
catch (oError) {
//Do nothing
}
}
}
throw new Error("XMLHttp object could be created.");
}


function CallWS(methodXml, methodName)
{
var xddoc, xhhttp, sxml
//alert(gc_lmsServicesPath);
// Create SOAP request
sxml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV = 'http://schemas.xmlsoap.org/soap/envelope/'>";
sxml = sxml + "<SOAP-ENV:Body>";
sxml = sxml + methodXml;
sxml = sxml + "</SOAP-ENV:Body>";
sxml = sxml + "</SOAP-ENV:Envelope>";

xddoc = createxddoc(sxml);
// Creating HTTP request
xhhttp = new createXMLHttp(sxml);
alert(gc_lmsServicesPath);

//BELOW LINE IS NOT EXECUTING WHEN SERVICE PATH GIVEN IN WEB CONGIF IS SERVER NAME(for ex : http://ClentServer/App_Name/Service.asmx ")
xhhttp.open("POST", gc_lmsServicesPath, false);

xhhttp.setRequestHeader("SOAPAction", "http://tempuri.org/" + methodName);
xhhttp.setRequestHeader("MessageType", "CALL");
xhhttp.setRequestHeader("Content-Type", "text/xml");
try
{
// Sending request to the web service by HTTP
xhhttp.send(xddoc);
xhhttp.close;
}
catch(e)
{
throw(e);
}
if(gc_ThirdPlmsServicesPath!="")
SecondCall(sxml, methodName);

// Getting response from Web Service
xddoc = result(xhhttp);
return xddoc;

}
In webconfig file Service path given as follows

<add key="Service" value="http://ServerName/Service.asmx"/>


Any ideas? Thanks.

b1randon's Avatar
Expert
 
Join Date: Dec 2006
Location: Pittsburgh
Posts: 171
#2: Jan 8 '07

re: XMLHttpRequest problem with Firefox and Netscape


Quote:

Originally Posted by ScriptProblem

Hi Guys,

I have a security concern with Mozilla and Netscape browsers(In IE it gives secuirity pop window) in Remote server(Client's server).When I am trying to call an Asp.NET web service from javascript using the XmlHttpRequest object

XmlHttpRequest .Open("POST", ServicesPath, false);

Problem is only in Cleint's server ,Where in web Service path given in Webconfig file is server name(not the Ip Address, We noticed that Client is using same IP number with diffrent Port number to access the diffrent application. I.e The server IP number and a port also used to access this application). I think it works fine, if we mention webservice path as IP Number with the correct PORT number. which combination is used to access the application. But we cannot modify the Host file in Client machine.

It works beautifully! in local server , where we are modifying the local host file by regestering the IP number with name, and using name in webconfig file to give service path.

CODE SNIPPET :

function createXMLHttp(sxml)
{
if (typeof XMLHttpRequest != "undefined") {
return new XMLHttpRequest();
}
else if (window.ActiveXObject) {
var aVersions = [ "MSXML2.XMLHttp.5.0",
"MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
"MSXML2.XMLHttp","Microsoft.XMLHttp"];

for (var i = 0; i < aVersions.length; i++) {
try {
var oXmlHttp = new ActiveXObject(aVersions[i]);
return oXmlHttp;
}
catch (oError) {
//Do nothing
}
}
}
throw new Error("XMLHttp object could be created.");
}


function CallWS(methodXml, methodName)
{
var xddoc, xhhttp, sxml
//alert(gc_lmsServicesPath);
// Create SOAP request
sxml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV = 'http://schemas.xmlsoap.org/soap/envelope/'>";
sxml = sxml + "<SOAP-ENV:Body>";
sxml = sxml + methodXml;
sxml = sxml + "</SOAP-ENV:Body>";
sxml = sxml + "</SOAP-ENV:Envelope>";

xddoc = createxddoc(sxml);
// Creating HTTP request
xhhttp = new createXMLHttp(sxml);
alert(gc_lmsServicesPath);

//BELOW LINE IS NOT EXECUTING WHEN SERVICE PATH GIVEN IN WEB CONGIF IS SERVER NAME(for ex : http://ClentServer/App_Name/Service.asmx ")
xhhttp.open("POST", gc_lmsServicesPath, false);

xhhttp.setRequestHeader("SOAPAction", "http://tempuri.org/" + methodName);
xhhttp.setRequestHeader("MessageType", "CALL");
xhhttp.setRequestHeader("Content-Type", "text/xml");
try
{
// Sending request to the web service by HTTP
xhhttp.send(xddoc);
xhhttp.close;
}
catch(e)
{
throw(e);
}
if(gc_ThirdPlmsServicesPath!="")
SecondCall(sxml, methodName);

// Getting response from Web Service
xddoc = result(xhhttp);
return xddoc;

}
In webconfig file Service path given as follows

<add key="Service" value="http://ServerName/Service.asmx"/>


Any ideas? Thanks.

If it works on local only then your problem is probably that for security reasons most browsers will only let you call XMLRequests to the same domain as the page came from (unless the page is locally hosted which explains why it works locally). The only way around this is either to a) be synchronous and call a page so that your server can access the web service or b) stay asynchronous but use an ajax call to your server which will call your WS, then return it's results back to the browser. It's a hairy mess, I know, but it is one of the only ways to keep web pages from making calls all over the web without the client realizing it.
Reply