473,386 Members | 1,758 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.

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_speech.GenerateSpeechDataForText"
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(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService_speech : System.Web.Services.WebService
{
public System.Speech.Synthesis.SpeechSynthesizer TtsVoice;

public WebService_speech()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}

public delegate string GenerateSpeechDataForTextAsyncStub(string
text);

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

//state monitor for the GenerateSpeechDataForText service
public class MyState
{
public object previousState;
public GenerateSpeechDataForTextAsyncStub asyncStub;
}

//start the GenerateSpeechDataForText method
[WebMethod]
public IAsyncResult BeginGenerateSpeechDataForText(string text,
AsyncCallback cb, object s)
{
GenerateSpeechDataForTextAsyncStub stub = new
GenerateSpeechDataForTextAsyncStub(GenerateSpeechD ataForText);
MyState ms = new MyState();
ms.previousState = s;
ms.asyncStub = stub;
return stub.BeginInvoke(text, cb, ms);
}

//end the GenerateSpeechDataForText method
[WebMethod]
public SpeechData EndGenerateSpeechDataForText(IAsyncResult call)
{
MyState ms = (MyState)call.AsyncState;
return ms.asyncStub.EndInvoke(call);
}
}


Thx a million,
matt
Dec 12 '07 #1
2 5528
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.com 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_speech.GenerateSpeechDataForText"
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(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService_speech : System.Web.Services.WebService
{
public System.Speech.Synthesis.SpeechSynthesizer TtsVoice;

public WebService_speech()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}

public delegate string GenerateSpeechDataForTextAsyncStub(string
text);

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

//state monitor for the GenerateSpeechDataForText service
public class MyState
{
public object previousState;
public GenerateSpeechDataForTextAsyncStub asyncStub;
}

//start the GenerateSpeechDataForText method
[WebMethod]
public IAsyncResult BeginGenerateSpeechDataForText(string text,
AsyncCallback cb, object s)
{
GenerateSpeechDataForTextAsyncStub stub = new
GenerateSpeechDataForTextAsyncStub(GenerateSpeechD ataForText);
MyState ms = new MyState();
ms.previousState = s;
ms.asyncStub = stub;
return stub.BeginInvoke(text, cb, ms);
}

//end the GenerateSpeechDataForText method
[WebMethod]
public SpeechData EndGenerateSpeechDataForText(IAsyncResult call)
{
MyState ms = (MyState)call.AsyncState;
return ms.asyncStub.EndInvoke(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 "
GenerateSpeechDataForText").
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
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...
5
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...
4
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...
3
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...
0
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...
2
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...
4
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...
1
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...
0
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 =...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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,...

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.