Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-11-2012, 06:43 PM   PM User | #1
mmy
New to the CF scene

 
Join Date: Jan 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mmy is an unknown quantity at this point
using a webservice - problem with webservice.htc ?

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 - but the error remains)

This is my testing code:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test service</title>
<script type="text/javascript" language="javascript">

function init()
{
    try
    {
        websrvCaller.useService("http://intranet/testservices/service1.asmx?wsdl","myService");
    }
    catch (e)
    {
        alert(e);    
    }
}

function test()
{
    websrvCaller.myService.callService(myCallback,"HelloWorld", "Asynchronous Call");    
}

function myCallback(res)
{
    if (!res.error) 
    {
        alert("Successful call. Result is " + res.value);
      }
      else 
    {
        alert("Unsuccessful call. Error is " + res.errorDetail.string);
      }    
}
</script>

</head>

<body ID="websrvCaller" onload="init()" STYLE="behavior:url(webservice.htc);" >
    <input type="button" id="btnTest" value="test" onclick="test();" />
</body>
</html>
The first init() service triggers the error... Anybody knows what I'm missing here?
mmy is offline   Reply With Quote
Old 01-12-2012, 07:33 AM   PM User | #2
mmy
New to the CF scene

 
Join Date: Jan 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mmy is an unknown quantity at this point
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?
mmy is offline   Reply With Quote
Old 01-12-2012, 09:34 AM   PM User | #3
mmy
New to the CF scene

 
Join Date: Jan 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mmy is an unknown quantity at this point
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
Code:
<!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...

Last edited by mmy; 01-12-2012 at 12:15 PM..
mmy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:31 PM.


Advertisement
Log in to turn off these ads.