Calling WebService from JavaScript

D

Danijel Valentic

Hello!

I have a WebService called MyWebService with webMethod returnMyNumber(string
like). Now I need to call it from JavaScript and get the returned DataSet.
How can I do this?

Thanks everyone
 
R

Robert Koritnik

WebService Enhancements, which incorporates DIME protocol that you could use
here... Free reom Microsoft... Check MSDN site.
 
D

Danijel Valentic

thnx Alvin. This page is OK, it has a lot of information, but there is
one thing that bothers me...

On the

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/webse
rvice/overview.asp

page is writen:
"The WebService behavior is encapsulated in an HTC file. Therefore,
before you begin using the behavior in your own Web pages, download the
WebService HTC File and copy it to a folder in your Web project."

The "WebService HTC File" is link to this page:

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples
/internet/welcome.asp

And now I don't understand this: I have my own WebService. Do I have to
download the htc file anyway or not? Do I have to make my own htc
file(and if so how )?

And if I have to download it how? I don't know how to download from the
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples
/internet/welcome.asp

page.

Thanks again
 
L

Lee_Nover

OK, I have downloaded the .htc file...

from where ? couldn't find it .. the one in the article is archived and
not available :/
tnx (hvala :p)
 
D

Danijel Valentic

I did what is writen on the microsoft pages. I have:

<DIV ID="service" STYLE="BEHAVIOR:url(webservice.htc)"></DIV> (inside
<body></body>),

<script language="javascript">
function init()
{
service.useService ("http://localhost/Beseda/VrniBesedo.asmx?
WSDL", "vrniPodatkeWebService" );
}
</script> (inside <head></head>)

and
<body MS_POSITIONING="GridLayout" onload="init()">.


But I get a error message:
An error has occurred in the script on this page.
Object does not support this property or method


What's wrong?
thnx
 
D

Danijel Valentic

OK. Now I need to populate a dataGrid with the data in the dataSet the
webservice returns...

any idea?

thnx
 
R

Robert Koritnik

Ni panike...

but it would probably be better (for the sake of others) to talk in english
or we will be warned. ;)
 
R

Robert Koritnik

HTC is for your web service consumer application which will call the web
service from the client side. Your web service app doesn't need the HTC.
 
R

Robert Koritnik

As far as I'm concerned, that's a more tough one. "Normally" web services
return more simple types as DataSets. Updating DataGrid with it would be:
1. VERY complicated thing to do, while changing the whole server control on
the client could end up in complicated problems on the server side when the
HTTP_POST occures. You should be VERY familiar how a DataGrid behaves to do
this.
2. Quite complicated client script to get the job done.

Still it's possible, but I don't think that any of us is going to write this
for you. Too many specifics and too much work with no real result. I
seriously doubt that anyone would use it...

Just a suggestion.

If you have to update your DataGrid and are already calling a web service
somewhere on some server you could easily just postback and do this on the
serverside.

Calling a webservice from the client is more meant to be used:
1. with more simple types to update a small portion of the UI (a label, or a
small amount of controls on the client) while a VERY SMALL amount of data is
transfered back and forth instead of large data transfers of the whole
pages, pictures etc.
2. to transfer LARGE posts TO the server with other types of encoding than
Base64 which makes a large post even more larger (transfering files using
DIME instead of the normal way)
 
D

Danijel Valentic

Hello again!

I've done everything I needed and now I have a new problem:

I've realized the WebService as an undependent project.
Than I've added the WebReference to it. Now I want to deploy my
Application to the server and I get this error:

... webService is null or not an object.

How can I deploy it?

Thnx for all of your help, d
 
H

Howard Rothenburg

There is a good example of this at

http://www.c-sharpcorner.com/Code/2002/May/HTMLClient4WebServices.asp

It shows the client and the server

Here is the client:

<SCRIPT language="JavaScript">
var iCallID;

function ExecuteWS()
{

iCallID = service.Calculator.callService("Add",num1.value,num2.value);
}

function onWSresult()
{
if((event.result.error)&&(iCallID==event.result.id))
{
var xfaultcode = event.result.errorDetail.code;
var xfaultstring = event.result.errorDetail.string;
var xfaultsoap = event.result.errorDetail.raw;
document.writeln("ERROR. Method call failed!");
document.writeln("Call ID:" + iCallID);
document.writeln("Fault Code:" + xfaultcode);
document.writeln("Fault String:" + xfaultstring);
document.writeln("SOAP Data:" + xfaultsoap);
}
else if(event.result.error == false)
{
sum.value= event.result.value;
}
}
</script>
<body onload= "service.useService('http://localhost/site/code/testws.asmx?WSDL','Calculator');">
<div id="service" style="behavior:url(webservice.htc)"
onresult="onWSresult()">
</div>


Number : <input type="text" name='num1'\">
Number : </td><td><input type="text" name='num2'\">
Total:<input type="text" name='sum'\">
<button OnClick="ExecuteWS()">Add Numbers</button>
</body>


You also need to download webservice.htc from MS at
http://msdn.microsoft.com/archive/en-us/samples/internet/behaviors/library/webservice/webservice.htc



Alvin Bruney said:
you need behaviors for that
start here
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/webservice/overview.asp

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Danijel Valentic said:
Hello!

I have a WebService called MyWebService with webMethod
returnMyNumber(string like). Now I need to call it from JavaScript and get
the returned DataSet. How can I do this?

Thanks everyone
 
D

David

I've posted question after question to various NG's about that fact that MS
has "archived" webservice.htc, and what is the replacement? But haven't
gotten any viable responses (unless you consider "use xmlHttp to transport
your soap envelope" to be a "viable" alternative...arrrgh).

But I continue to see people recommending the use of webservice.htc, while
no one is questioning the wisdom of using an "archived" component for new
development!

So, is WSE the functional "replacement/successor" to what webservice.htc
provides (or should I say "provideD")?

David
 
D

David

I KNOW where the webservice.htc component is located. We've used it for a
couple of years now.

The question was (and IS): what is the functional replacement for
webservice.htc now that it has been "archived" (aka, "obsolete").

David
 
L

Lee_Nover

I KNOW where the webservice.htc component is located. We've used it for a
couple of years now.

The question was (and IS): what is the functional replacement for
webservice.htc now that it has been "archived" (aka, "obsolete").


oh .. sorry .. dunno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top