Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / November 2005

Tip: Looking for answers? Try searching our database.

Calling a webservice within a HTA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Allister  Farn - 15 Nov 2005 17:11 GMT
I have created a HTA from which I need to call a .NET webservice. I've
written the HTA to use the webservice.htc behaviour, but am wondering
if there is a better way. I am trying to limit the number of "advanced"
steps the users need to carry out (i.e. savnig files, downloading other
files to the same directory etc).

The scenario is as follows:

The user needs to download a report that requires user input, and they
need to save the report to their local file system, as they have to
provide input to the report when they are offline.

The user then goes online at a later stage, re-opens the report and
clicks on a Submit button which validates the report content, and then
calls a webservice passing a long string which is the data collected
via the report.

The web service then processes, validates and saves this data, and
returns either a success value or an error to the HTA, which is
displayed to the user.

Because it is not possible to reference webservice.htc using a http url
within the HTA, it appears that it is necessary for the user to
download and save the webservice.htc file to the same directory as
where they'll be saving the HTA. I'd prefer to avoid this step if
possible.

Can you please suggest other ways in which this functionality can be
provided?
Martin Honnen - 15 Nov 2005 18:40 GMT
Allister Farn wrote:

> I have created a HTA from which I need to call a .NET webservice. I've
> written the HTA to use the webservice.htc behaviour, but am wondering
> if there is a better way.

> The user then goes online at a later stage, re-opens the report and
> clicks on a Submit button which validates the report content, and then
[quoted text clipped - 4 lines]
> returns either a success value or an error to the HTA, which is
> displayed to the user.

> Can you please suggest other ways in which this functionality can be
> provided?

If you want to do it with script and all the web service gets is some
string and all the web service returns is some success value then you
could consider using MSXML, DOMDocument and XMLHTTP object to construct
the rather simple SOAP message, POST it to the service with the SOAP
action set as an HTTP request header, and receive and parse the rather
simple response. Of course the web service behavior or the SOAP toolkit
free you from dealing with SOAP yourself and in general it is easier and
more reliable to use such tools than dealing with SOAP itself but if you
don't want to install anything but have HTA support on the client then
MSXML as installed by IE is already available. The web service behavior
uses MSXML anyway.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

farnsy@gmail.com - 16 Nov 2005 17:06 GMT
Can you please confirm that it's as simple as the following:

var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");

function sendData() {
    xmlhttp.onreadystatechange = doHttpReadyStateChange;

    var sendString = "test";

    xmlhttp.Open("POST",
"http://servername/servicename/Service1.asmx/operationname", true);

    xmlhttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-Length", sendString.length);
    xmlhttp.send("doc="+sendString);
}

function doHttpReadyStateChange(){
    if (xmlhttp.readyState == 4) {
        alert(xmlhttp.responsetext);
        var str = xmlhttp.responsetext;
   }
}

I was messing around trying to create soap packets and having a lot of
trouble with things, and then this worked.

What should I be aware of with regards to the status property, and the
readystate property? What event/action will occur if the post times
out?

thanks for your help.
Martin Honnen - 17 Nov 2005 17:12 GMT
> Can you please confirm that it's as simple as the following:
>
[quoted text clipped - 10 lines]
>     xmlhttp.setRequestHeader("Content-Type",
> "application/x-www-form-urlencoded");

You were talking about a web service used with the web service behavior
and that means to me the client so far made SOAP requests. If you now
switch to application/x-www-form-urlencoded requests then you need to
make sure that service expects/allows/understands such requests. It is
possible to configure .NET web services that way but not the default I
think.

>     xmlhttp.setRequestHeader("Content-Length", sendString.length);
>     xmlhttp.send("doc="+sendString);

If you want to send the request with the content type
application/x-www-form-urlencoded then your script needs to make sure
the argument to send is in that encoding, with JScript (as supported in
IE 5.5 and later) you could do
  xmlhttp.send("doc=" + encodeURIComponent(sendString));

> function doHttpReadyStateChange(){
>     if (xmlhttp.readyState == 4) {
>         alert(xmlhttp.responsetext);
>         var str = xmlhttp.responsetext;

There is no standard defined I think what format a response to such a
HTTP POST request to a web service should have but I think .NET services
still answer with an XML document so consider using responseXML and
accessing it with DOM and not using responseText. Check the
documentation for that service what kind of answers it gives.

> What should I be aware of with regards to the status property, and the
> readystate property?

It is HTTP so the xmlhttp.status property gives you the HTTP response
status code the server sends, those are defined here:
  <http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1>

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Martin Honnen - 17 Nov 2005 18:17 GMT
>     xmlhttp.setRequestHeader("Content-Length", sendString.length);
>     xmlhttp.send("doc="+sendString);

Forgot to mention, if you want to set Content-Length then you need to
set it to the complete length of the string argument of the send method
so do e.g.
  var body = "doc=" + encodeURIComponent(sendString);
  xmlhttp.setRequestHeader("Content-Length", body);
  xmlhttp.send(body);

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.