473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

JavaScript & Webservice - problem with webservice.htc ?

4
Hi,

I'm trying to consume a webservice (default HelloWorld created in Visual Studio 2010 / ASP.NET web application)

The .asmx file is located on my local network. When I enter the URL in my browser (http://intranet/testservices/service1.asmx), I see the webservices, ... So I'm sure this page is ok.

Now I'm trying to consume this webservice using an HTML doc with JavaScript.

I looked for some tutorials on the net, all the examples say I should place "webservice.htc" in the same folder as my HTML doc (and refer to it using the 'id' and 'style' attribute in an element - I used it in the body tag)

However, when calling ".useService" I receive an error "TypeError: Object doesn't support property or method 'useService'" (tested with IE9, Chrome16, FF5.0)

I looked into the webservice.htc file (version 1.0.1.810) and there is a public method called useService (when I use Visual Studio and debug the code, I see it enters the useService function in the htc file)

This is my testing code:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>test service</title>
  6. <script type="text/javascript" language="javascript">
  7.  
  8. function init()
  9. {
  10.     try
  11.     {
  12.         websrvCaller.useService("http://intranet/testservices/service1.asmx?wsdl","myService");
  13.     }
  14.     catch (e)
  15.     {
  16.         alert(e);    
  17.     }
  18. }
  19.  
  20. function test()
  21. {
  22.     websrvCaller.myService.callService(myCallback,"HelloWorld", "Asynchronous Call");    
  23. }
  24.  
  25. function myCallback(res)
  26. {
  27.     if (!res.error) 
  28.     {
  29.         alert("Successful call. Result is " + res.value);
  30.       }
  31.       else 
  32.     {
  33.         alert("Unsuccessful call. Error is " + res.errorDetail.string);
  34.       }    
  35. }
  36. </script>
  37.  
  38. </head>
  39.  
  40. <body ID="websrvCaller" onload="init()" STYLE="behavior:url(webservice.htc);" >
  41.     <input type="button" id="btnTest" value="test" onclick="test();" />
  42. </body>
  43. </html>
The first init() service triggers the error... Anybody knows what I'm missing here?
Jan 11 '12 #1
2 6842
mmy
4
EDIT: it seems the problem is caused that the webservice is located on another server. When I use the same webserver (Win server with IIS) for the HTML files and webservice they seem to work ok.

test fails when:
- html = located on my laptop, running a wamp webserver
- webservice = located on a windows server running iis (the server and my laptop are in the same local network)

Maybe these are security settings?
Jan 12 '12 #2
mmy
4
EDIT: sorry, but seems I was wrong in my last reply.
it seems the script only runs when I double click the html file (on my laptop or webserver, depending where it's located). When I open the page typing the URL (http://localhost....) I receive an error (all the HTML objects are ok, so I can load the page)

EDIT2: ok...one step further -> seems the first rule
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
is causing the error. When I remove this, everything works fine....For IE only! Seems FF, Chrome, ... can't just use JavaScript to interact with webservices. Search on google says you should use AJAX in ASP.NET or jquery. So, I'm going to study jquery for this one...
Jan 12 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Davie | last post by:
I want to authorise a user of a web service by using the AuthHeaderValue for some reason I keep getting a null reference exception when I try to run the following code: It seems to work fine on a...
4
by: Chris Bardon | last post by:
I'm working on an application where I need to be able to call a .net web service from javascript. I found the webservice.htc file, and was able to create a page that worked just fine, except that...
7
by: stephan querengaesser | last post by:
hi ng, i try to invoke a webservice-method with an filter-object, that contains value types. if i donīt want to filter the return value of the method, i have to pass a new instance of the...
4
by: WStoreyII | last post by:
I wish to know how to set it up so that when an xml webservice is called that instead of displaying the xml in the browser it will render it with a xslt file the problem is i dont know how to do...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
0
by: alberich | last post by:
I have a problem securing my webservice with Windows authentication. The goal is a client app transfering (large amounts of) data to a server which is blocked for anonymous requests. To do this,...
0
by: batista | last post by:
Hello all, I am using a webpage having a grid and im calling a webservice method(using webservice.htc) which after 5 seconds updates the content of the grid, uptil now everything is working...
4
by: linusthefish | last post by:
Is it possible to use JavaScript & MySQL? What I'm looking to do is query a database and then output the results in a popup window. I've got the popup window part down, I just can't figure out...
3
by: zion | last post by:
Hello, How can I return image link with webservice that I could see it in web page? The image is on my hard disk and <img src="c:\pictures\test.jpg" /does not work. If I use <img src=http://My...
3
by: mdallal | last post by:
i have a webpage that use javascript that call some method in a webservice, the webservice is registered into scriptManager of the masterPage of my web application. the page works fine at the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.