XmlHttp can access webservices from javascript, but not from within applications?

  • Thread starter Thread starter DSmith1974
  • Start date Start date
D

DSmith1974

Hi All,

After creating an end-point with batches enabled using SQL Server 2005,
I can easily query a database and have xml returned from within
javascript using something like Pablo's code (below).

But, if I try the same code from VB6 or VB.NET (a straight forward port
- swap ActiveXObject for CreateObject, remove ';'s etc) I always get
'Incorrect Parameter' on the send method of xmlhttp.

Why should it work from script but not applications, could it be that
the request headers need to be different or are somehow 'more correct'
when issued from within an ecma environment?

Many thanks,

Duncan.

---Javascript sample:
http://weblogs.asp.net/cibrax/archive/2005/04/22/403868.aspx---
function SendBatchRequest( strServerName, strUrlPath, strQuery )
{
var objXmlHttp = null;
var strRequest = "";

objXmlHttp = new ActiveXObject( "microsoft.xmlhttp" );
objXmlHttp.open( "POST", "http://" + strServerName + strUrlPath,
false );
objXmlHttp.setrequestheader( "Content-Type", "text/xml" );
objXmlHttp.setRequestHeader( "Host", strServerName );

strRequest = "<SOAP-ENV:Envelope

xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'

xmlns:sql='http://schemas.microsoft.com/sqlserver/2004/SOAP'>
<SOAP-ENV:Body>
<sql:sqlbatch>
<sql:BatchCommands>" + strQuery +
"</sql:BatchCommands>
</sql:sqlbatch>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>";

objXmlHttp.send( strRequest );

if( objXmlHttp.status == 200 )
return objXmlHttp.responseXML.xml;
else
return "";
}

var response = SendBatchRequest( 'localhost', '/sql/myendpoint',
'Select * from sys.http_endpoints' );
------
 
Back
Top