Home All Groups Group Topic Archive Search About

HTML AJAX to DOT.NET in Different Domain

Author
21 Feb 2007 7:47 PM
Thom Little
I am looking for an example of ...

- HTML or ASP 3 page using AJAX
- ASP.NET 2.0 web service in a different domain

HTML or ASP 3 pages passes a string to Web Service and it returns an XML
packaged string to the client.

_______________________________________________
Thom Little    www.tlanet.net    Thom Little Associates, Ltd.

Author
21 Feb 2007 7:53 PM
Michael Nemtsev
Hello Thom,

TL> I am looking for an example of ...
TL> - HTML or ASP 3 page using AJAX

See there http://www.dotnetjunkies.com/WebLog/joshuagough/archive/2005/11/21/133916.aspx

TL> - ASP.NET 2.0 web service in a different domain

What do u mean?

---
WBR,  Michael  Nemtsev [C# MVP]. 
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
Author
22 Feb 2007 3:10 AM
Thom Little
Thanks for the lead.

_______________________________________________
Thom Little    www.tlanet.net    Thom Little Associates, Ltd.


On 21-Feb-2007, Michael Nemtsev <nemt***@msn.com> wrote:

Show quote
Author
5 Mar 2007 4:52 PM
Thom Little
For the record ... this is the sample that I hopped someone could have
pointed me to it runs in FireFox, Internet Explorer, Netscape, and Opera)
....

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
   <head>
      <title>AJAX Calling ASP.NET</title>
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <script type="text/javascript">

// ASP.NET WebService
//    location - http://www.somedomain.com/Service/HelloWorldString.asmx
//    namespace - http://www.somedomain.com/service/
//    method - HelloWorldString( string strParm )
// HTML page
//    location - http://www.somedomain.com/sample.html

         function AjaxRequest( counterName )
            {
            if ( window.XMLHttpRequest )
               request = new XMLHttpRequest( );
            else if ( window.ActiveXObject )
               {
               request = new ActiveXObject( "Msxml2.XMLHTTP" );
               if ( ! request )
                  request = new ActiveXObject( "Microsoft.XMLHTTP" );
               }
            if ( request )
               {
               var strWork =
                  "<soap:Envelope
       xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
       xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
       xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
                  "<soap:Body>" +
                  "<helloworldstring
       xmlns=\"http://www.somedomain.com/service/\">" +
                  "<strParm>" + counterName + "</strParm>" +
                  "</helloworldstring>" +
                  "</soap:Body>" +
                  "</soap:Envelope>"
               request.onreadystatechange = AjaxResponse ;
               request.open( "POST",
       "http://www.somedomain.com/Service/HelloWorldString.asmx", true );
               request.setRequestHeader( "Content-Type", "text/xml" );
               request.setRequestHeader( "SOAPAction",
       "http://www.somedomain.com/service/helloworldstring" );
               request.send( strWork );
               }
            else
               alert( "Browser does not support all application features."
       );
            return ;
            }

         function AjaxResponse( )
            {
            if ( request.readyState == 4 )
               {
               if ( request.status == 200 )
                  document.getElementById("divString").innerHTML
       =request.responseXML.documentElement.getElementsByTagName("countResult")[0].firstChild.data;
               else
                  alert( "Error - " + request.status + " - " +
       request.statusText );
               }
            return ;
            }
      </script>
   </head>

   <body bgcolor="gainsboro">
      <table border="2" cellpadding="16" cellspacing="2">
         <tr>
            <td align="center">
               <p><br /><b>AJAX Test</b>
               <form action="javascript:void%200"
       onclick="AjaxRequest('one');return false">
                  <button type="submit">Update</button></p>
               </form>
               <p><div id="divString"></div>
            </td>
         </tr>
      </table>
   </body>
</html>

_______________________________________________
Thom Little    www.tlanet.net    Thom Little Associates, Ltd.
Author
22 Feb 2007 12:35 AM
Göran_Andersson
Thom Little wrote:
> I am looking for an example of ...
>
> - HTML or ASP 3 page using AJAX

Neither is possible. You can't do it using plain HTML, and ASP code is
run on the server, not in the browser. You need to use Javascript.

> - ASP.NET 2.0 web service in a different domain

Unless you are using a web service to communicate between two servers,
you are almost always using a web service in a different domain.

>
> HTML or ASP 3 pages passes a string to Web Service and it returns an XML
> packaged string to the client.
>
> _______________________________________________
>  Thom Little    www.tlanet.net    Thom Little Associates, Ltd.


--
Göran Andersson
_____
http://www.guffa.com
Author
22 Feb 2007 2:56 AM
Thom Little
I seem to be mumbling ... sorry ...

I want to call an ASP.NET web service from an HTML or ASP 3 page that is
using JavaScript/AJAX.  This call will pass a single string to the web
service and the web service will pass a single sting back to the HTML or ASP
3 page to be processed by the JavaScript/AJAX that they contain.

The examples I have found to date are HTML/AJAX and the server side is not
provided or ASP.NET on both sides where the JavaScript/AJAX is obscured.

If I can get this trivial application cycling I will understand how
JavaScript/AJAX is wired AND solve the issue FINALLY of being able to call a
Web Service from an HTML/JavaScript/AJAX or ASP3/JavaScript/AJAX page that
is rendered on ANY browser.

For the simplest case assume that the caller and called pages are both in
the same domain.  I will work out the proxy processing for separated domains
later.

My objective is to be able to add incremental improvements to existing HTML
or ASP 3 pages using AJAX to access new web services.

_______________________________________________
Thom Little    www.tlanet.net    Thom Little Associates, Ltd.


On 21-Feb-2007, =?ISO-8859-1?Q?G=F6ran_Andersson?= <gu***@guffa.com> wrote:

Show quote
> > - HTML or ASP 3 page using AJAX
>
> Neither is possible. You can't do it using plain HTML, and ASP code is
> run on the server, not in the browser. You need to use Javascript.
>
> > - ASP.NET 2.0 web service in a different domain
>
> Unless you are using a web service to communicate between two servers,
> you are almost always using a web service in a different domain.
Author
22 Feb 2007 11:27 AM
Göran_Andersson
The web service and the code that uses it work independently. You can
pick the client side from one example, and the server side from another,
and just change the information that is sent and recieved.

If you build a web service in ASP.NET you can browse to it to see the
information pages about it. There you see all the methods that it has,
exactly what you send to them, and what they return.

As AJAX uses HTTP to communicate, you rarely have to care about any
proxy settings. If the browser can browse to the service, so can the
Javascript that runs in the browser.

Thom Little wrote:
Show quote
> I seem to be mumbling ... sorry ...
>
> I want to call an ASP.NET web service from an HTML or ASP 3 page that is
> using JavaScript/AJAX.  This call will pass a single string to the web
> service and the web service will pass a single sting back to the HTML or ASP
> 3 page to be processed by the JavaScript/AJAX that they contain.
>
> The examples I have found to date are HTML/AJAX and the server side is not
> provided or ASP.NET on both sides where the JavaScript/AJAX is obscured.
>
> If I can get this trivial application cycling I will understand how
> JavaScript/AJAX is wired AND solve the issue FINALLY of being able to call a
> Web Service from an HTML/JavaScript/AJAX or ASP3/JavaScript/AJAX page that
> is rendered on ANY browser.
>
> For the simplest case assume that the caller and called pages are both in
> the same domain.  I will work out the proxy processing for separated domains
> later.
>
> My objective is to be able to add incremental improvements to existing HTML
> or ASP 3 pages using AJAX to access new web services.
>
> _______________________________________________
>  Thom Little    www.tlanet.net    Thom Little Associates, Ltd.
>
>
> On 21-Feb-2007, =?ISO-8859-1?Q?G=F6ran_Andersson?= <gu***@guffa.com> wrote:
>
>>> - HTML or ASP 3 page using AJAX
>> Neither is possible. You can't do it using plain HTML, and ASP code is
>> run on the server, not in the browser. You need to use Javascript.
>>
>>> - ASP.NET 2.0 web service in a different domain
>> Unless you are using a web service to communicate between two servers,
>> you are almost always using a web service in a different domain.


--
Göran Andersson
_____
http://www.guffa.com
Author
22 Feb 2007 3:13 PM
Thom Little
Yes like most things in our business the solution will be obvious and dumb
after it is found.

The web service is called correctly from an .aspx page with ...

this.lblCount.Text = service.count( "test.counter" );
.... where "service" is a web service proxy containing one method that is
"count( )".
My HTML/JavaScript/AJAX call to the service is installed on
micron.tlanet.net and is currently throwing an error 500 and it looks like
....

function Send( )
    {
    var frm = document.forms[0] ;
    queryString = encodeURIComponent( frm.elements[0].value );
    Request( "POST",
    "http://micron.tlanet.net/Service/CountService.asmx?op=count", true );
    return ;
    }

function Request( reqType, url, async )
    {
    if ( window.XMLHttpRequest )
        request = new XMLHttpRequest( );
    else if ( window.ActiveXObject )
        {
        request = new ActiveXObject( "Msxml2.XMLHTTP" );
        if ( ! request )
            request = new ActiveXObject( "Microsoft.XMLHTTP" );
        }
    if ( request )
        {
        request.onreadystatechange = Response ;
        request.open( reqType, url, async );
        request.setRequestHeader( "Content-Type",
        "application/x-www-form-urlencoded; charset=UTF-8" );
                request.overrideMimeType( "text/XML" );
        request.send( "arbitrary_string" );
        }
    else
        alert( "Browser does not support all application features." );
    return ;
    }

function Response( )
    {
    if ( request.readyState == 4 )
        {
        if ( request.status == 200 )
            {
            alert( request.responseText );
            stylizeDiv( getDocInfo( request.responseXML ), document.getElementById(
            "docDisplay" ) );
            }
        else
            alert( "Request Status = " + request.status + " = " + request.statusText
            );
        }
    return ;
    }

If you see the obvious solution to my dumb mistake, pleas point it out.  (My
current assumption is that "url/method" is incorrectly specified.)

_______________________________________________
Thom Little    www.tlanet.net    Thom Little Associates, Ltd.
Author
24 Feb 2007 12:42 AM
Göran_Andersson
Thom Little wrote:
Show quote
> Yes like most things in our business the solution will be obvious and dumb
> after it is found.
>
> The web service is called correctly from an .aspx page with ...
>
> this.lblCount.Text = service.count( "test.counter" );
> ... where "service" is a web service proxy containing one method that is
> "count( )".
> My HTML/JavaScript/AJAX call to the service is installed on
> micron.tlanet.net and is currently throwing an error 500 and it looks like
> ...
>
> function Send( )
>     {
>     var frm = document.forms[0] ;
>     queryString = encodeURIComponent( frm.elements[0].value );
>     Request( "POST",
>     "http://micron.tlanet.net/Service/CountService.asmx?op=count", true );
>     return ;
>     }
>
> function Request( reqType, url, async )
>     {
>     if ( window.XMLHttpRequest )
>         request = new XMLHttpRequest( );
>     else if ( window.ActiveXObject )
>         {
>         request = new ActiveXObject( "Msxml2.XMLHTTP" );
>         if ( ! request )
>             request = new ActiveXObject( "Microsoft.XMLHTTP" );
>         }
>     if ( request )
>         {
>         request.onreadystatechange = Response ;
>         request.open( reqType, url, async );
>         request.setRequestHeader( "Content-Type",
>         "application/x-www-form-urlencoded; charset=UTF-8" );
>                 request.overrideMimeType( "text/XML" );
>         request.send( "arbitrary_string" );
>         }
>     else
>         alert( "Browser does not support all application features." );
>     return ;
>     }
>
> function Response( )
>     {
>     if ( request.readyState == 4 )
>         {
>         if ( request.status == 200 )
>             {
>             alert( request.responseText );
>             stylizeDiv( getDocInfo( request.responseXML ), document.getElementById(
>             "docDisplay" ) );
>             }
>         else
>             alert( "Request Status = " + request.status + " = " + request.statusText
>             );
>         }
>     return ;
>     }
>
> If you see the obvious solution to my dumb mistake, pleas point it out.  (My
> current assumption is that "url/method" is incorrectly specified.)
>
> _______________________________________________
>  Thom Little    www.tlanet.net    Thom Little Associates, Ltd.

The web service expects a SOAP message that contains what method to
invode and the parameters for that method, not just a random string.

Browse to the web service to see an example of the input that it expects.

--
Göran Andersson
_____
http://www.guffa.com
Author
25 Feb 2007 12:48 AM
Thom Little
Yes I finally realized that.

I have been trying to create the appropriate control information for passing
an XML request to the service from an HTML page using JavaScrip/Ajax but
continue to get 500 errors.

If anyone has an example of passing an appropriately wrapped string in both
directions
HTML/JavasScript/Ajax to ASP.NET Web Service to HTML/JavaScript/Ajax I think
it would be VERY helpful.

Specifically it would be XmlHttpRequest to ASP.NET Web Service and back.

I think this is the toughest case and when it is cycling every other
permutation will just fall into place.

_______________________________________________
Thom Little    www.tlanet.net    Thom Little Associates, Ltd.

On 23-Feb-2007, =?ISO-8859-1?Q?G=F6ran_Andersson?= <gu***@guffa.com> wrote:

Show quote
> The web service expects a SOAP message that contains what method to
> invode and the parameters for that method, not just a random string.
>
> Browse to the web service to see an example of the input that it expects.

AddThis Social Bookmark Button