473,883 Members | 1,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do u call async webmethod from javascript!??!!

Hello to all!

I have a fairly simple webservice running in asp.net ajax under c# (vs
2008).
I built the service and it runs just dandy when i test it by itself in
visual studio.
However, to make it work, i had to break up the webmethod into the
BeginXXX, EndXXX model
as per http://msdn2.microsoft.com/en-us/library/aa480516.aspx
But now, i can no longer call this method from javascript (since to
use the BeginXXX, EndXXX, you must remove the [WebMethod] from the
orig method)
Specifically, in javascript i originally would be able to call the
service via
"WebService_spe ech.GenerateSpe echDataForText"
But after adding in the BeginXXX, and EndXXX, i no longer know how to
call the service from javascript
I feel like i'm so close, but i just dont know how to call my service.
Any ideas?

here's the code snippet from the service

WebService(Name space = "http://tempuri.org/")]
[WebServiceBindi ng(ConformsTo = WsiProfiles.Bas icProfile1_1)]
[System.Web.Scri pt.Services.Scr iptService]
public class WebService_spee ch : System.Web.Serv ices.WebService
{
public System.Speech.S ynthesis.Speech Synthesizer TtsVoice;

public WebService_spee ch()
{
//Uncomment the following line if using designed components
//InitializeCompo nent();
}

public delegate string GenerateSpeechD ataForTextAsync Stub(string
text);

//meat of the method (heavy lifting done here)
//where the actual speech data is extracted from the text
public SpeechData GenerateSpeechD ataForText(stri ng text)
{
//do speech stuff here
//i removed the processing code
return SpeechData_;
}

//state monitor for the GenerateSpeechD ataForText service
public class MyState
{
public object previousState;
public GenerateSpeechD ataForTextAsync Stub asyncStub;
}

//start the GenerateSpeechD ataForText method
[WebMethod]
public IAsyncResult BeginGenerateSp eechDataForText (string text,
AsyncCallback cb, object s)
{
GenerateSpeechD ataForTextAsync Stub stub = new
GenerateSpeechD ataForTextAsync Stub(GenerateSp eechDataForText );
MyState ms = new MyState();
ms.previousStat e = s;
ms.asyncStub = stub;
return stub.BeginInvok e(text, cb, ms);
}

//end the GenerateSpeechD ataForText method
[WebMethod]
public SpeechData EndGenerateSpee chDataForText(I AsyncResult call)
{
MyState ms = (MyState)call.A syncState;
return ms.asyncStub.En dInvoke(call);
}
}


Thx a million,
matt
Dec 12 '07 #1
2 5587
the async webmethod is only used from .net programs. with .net you use a
proxy stub that is generated to call the webservice. the aync methods
are part of the stub (that runs in the caller), and allow specification
of a completion delegate.

javascript calls the webservice directly (socket to port) and is always
async (the a in ajax). when javascript calls a webservice, you always
supply a completion delegate.

so to do async from javascript you call the standard webservice method.

-- bruce (sqlwork.com)

jo****@gmail.co m wrote:
Hello to all!

I have a fairly simple webservice running in asp.net ajax under c# (vs
2008).
I built the service and it runs just dandy when i test it by itself in
visual studio.
However, to make it work, i had to break up the webmethod into the
BeginXXX, EndXXX model
as per http://msdn2.microsoft.com/en-us/library/aa480516.aspx
But now, i can no longer call this method from javascript (since to
use the BeginXXX, EndXXX, you must remove the [WebMethod] from the
orig method)
Specifically, in javascript i originally would be able to call the
service via
"WebService_spe ech.GenerateSpe echDataForText"
But after adding in the BeginXXX, and EndXXX, i no longer know how to
call the service from javascript
I feel like i'm so close, but i just dont know how to call my service.
Any ideas?

here's the code snippet from the service

WebService(Name space = "http://tempuri.org/")]
[WebServiceBindi ng(ConformsTo = WsiProfiles.Bas icProfile1_1)]
[System.Web.Scri pt.Services.Scr iptService]
public class WebService_spee ch : System.Web.Serv ices.WebService
{
public System.Speech.S ynthesis.Speech Synthesizer TtsVoice;

public WebService_spee ch()
{
//Uncomment the following line if using designed components
//InitializeCompo nent();
}

public delegate string GenerateSpeechD ataForTextAsync Stub(string
text);

//meat of the method (heavy lifting done here)
//where the actual speech data is extracted from the text
public SpeechData GenerateSpeechD ataForText(stri ng text)
{
//do speech stuff here
//i removed the processing code
return SpeechData_;
}

//state monitor for the GenerateSpeechD ataForText service
public class MyState
{
public object previousState;
public GenerateSpeechD ataForTextAsync Stub asyncStub;
}

//start the GenerateSpeechD ataForText method
[WebMethod]
public IAsyncResult BeginGenerateSp eechDataForText (string text,
AsyncCallback cb, object s)
{
GenerateSpeechD ataForTextAsync Stub stub = new
GenerateSpeechD ataForTextAsync Stub(GenerateSp eechDataForText );
MyState ms = new MyState();
ms.previousStat e = s;
ms.asyncStub = stub;
return stub.BeginInvok e(text, cb, ms);
}

//end the GenerateSpeechD ataForText method
[WebMethod]
public SpeechData EndGenerateSpee chDataForText(I AsyncResult call)
{
MyState ms = (MyState)call.A syncState;
return ms.asyncStub.En dInvoke(call);
}
}


Thx a million,
matt
Dec 12 '07 #2
hi bruce,
thank you for responding.

I apologize for not being clear enough on my original post.
When i dont use the BeginXXX and EndXXX methodology, i can call the
webservice from javascript no problem (i.e. the method "
GenerateSpeechD ataForText").
But when i use the BeginXXX and EndXXX methodology, javascript no
longer knows of that method name.
Isnt that bizarre?
Any thought,
Thanks,
matt
Dec 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1976
by: Giovanni Bassi | last post by:
Hello Group, I am running an operation in a different thread. There are resources that are released when the thread is done running. This is done at the end of the execution as it raises an event, and then the operation handling this event calls threaded object's dispose method. The problem is: If an exception is thrown the event is never raised, the operation never executes dispose and my resources get stuck on the memory until the app...
5
3266
by: Paul Hasell | last post by:
Hi, I'm trying to invoke a web method asynchronously but just can't seem to get it to tell me when it has finished! Below is the code I am (currently) using: private void btnUpload_Click(object sender, System.EventArgs e) { try { SOPWebService.Client uploader = new
4
3229
by: Paul | last post by:
Hi, I've been struggling with this today, I'm developing a DotNet2.0 website in C# that needs to call a long running data query. Obviously this is a good candidate for an Asynchronous call, so the page can carry on rendering whilst the call is taking place and also returning the ASP.NET worker thread to service another page request (for scalability). I have developed a very basic asynchronous object (for testing, that reproduces the same...
3
3602
by: KaNos | last post by:
Hi, "robot script pages" are html+javascript pages, can be played in aspx player. So in this tech, robot call aspx player's function (an interface is sheared) and wait a result synchronously with a javascript method. I try it with GetCallbackEventReference but this tech works async. Could I use a javascript function with a sync call ? Thaks for responses,
0
962
by: karlag92 | last post by:
Using .Net 1.1, in our Windows Forms Application we were taking advantage of the async functionality that is auto generated by c# for Web Service calls. We were doing it almost exactly like the first example here: http://msdn2.microsoft.com/en-us/library/55xs7d7f(VS.71).aspx Out WebMethod however had a definition like something like this:
2
5226
by: Zeba | last post by:
Hi guys! I'm new to JS / Ajax; I've been trying to do an Ajax call to my Webservice ( I'm using C# for code-behind). I'm not using any of the libraries available. I am sending my CustID to the webservice and the webservice returns a Dataset that contains various customer details taken from database. I have tested that the Webservice itself works. But my ajax call is not working. My ajax call is something like :
4
13045
by: faraz | last post by:
I have a javascript function that i want to call masterpage load method called. I cant add onLoad event of body or table in master page. I have put the call to script function in <form>, it works on every pageLoad. seems my problem is solved. But when the pages uses UpdatePanel and it gets asynchronously postback. the function call at master page doesnt execute????? thought master page Load event gets called even when pages are in...
1
2119
by: jojoba | last post by:
Hi I am running asp.net ajax (vs 2008) I have the following webservice listed below. However, i have no idea how to call this from javascript. Originally, before i started using the BeginXXX and EndXXX as per http://msdn2.microsoft.com/en-us/library/aa480516.aspx I could easily call the webmethod via in this case "WebService_speech.GenerateSpeechDataForText" but now im not sure how to call it.
0
2407
by: anithaapr05 | last post by:
Dear All, I have try to call the webmethod inside a master page browser close javascript function.It not working. This is my scriptcode: function BrowserClose() { var getValues = "webmethod"; PageMethods.ClearValues(getValues,OnSucceeded);
0
9944
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9793
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11151
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10752
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10420
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9582
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
2
4225
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3238
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.