Home All Groups Group Topic Archive Search About

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

Author
15 Mar 2006 2:29 PM
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' );
------

Author
12 Apr 2006 6:43 AM
Umut Alev - MSFT
Could you provide the VB repro that does not work?

<DSmith1***@googlemail.com> wrote in message
Show quoteHide quote
news:1142432954.874060.277290@j33g2000cwa.googlegroups.com...
> 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' );
> ------
>