HighTechTalks DotNet Forums  

Async web service methods calls

Dotnet Framework (Webservices) microsoft.public.dotnet.framework.webservices


Discuss Async web service methods calls in the Dotnet Framework (Webservices) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Stefan Filip
 
Posts: n/a

Default Async web service methods calls - 10-17-2007 , 10:20 AM






Hello,

I'm trying to launch several async calls for different methods of a web
service, but I get this error when i'm trying to read the result (There was
an error during asynchronous processing. Unique state object is required for
multiple asynchronous simultaneous operations to be outstanding.). I read the
post at
http://forums.microsoft.com/MSDN/Sho...79895&SiteID=1, and I
get the same error, but I have async calls to different web service methods.
What should I do?
Thanks

Reply With Quote
  #2  
Old   
John Saunders [MVP]
 
Posts: n/a

Default Re: Async web service methods calls - 10-17-2007 , 11:56 AM






"Stefan Filip" <StefanFilip (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hello,

I'm trying to launch several async calls for different methods of a web
service, but I get this error when i'm trying to read the result (There
was
an error during asynchronous processing. Unique state object is required
for
multiple asynchronous simultaneous operations to be outstanding.). I read
the
post at
http://forums.microsoft.com/MSDN/Sho...79895&SiteID=1,
and I
get the same error, but I have async calls to different web service
methods.
What should I do?
You should use a unique state object. It's not a per-method. Thing.

--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer




Reply With Quote
  #3  
Old   
Stefan Filip
 
Posts: n/a

Default Re: Async web service methods calls - 10-18-2007 , 04:16 AM



Thanks for answering John, but I already did that. Here's how my code looks
like:

languageReady = false;
contestReady = false;
usercontrolsReady = false;

backendService.GetControlsConstantsCompleted += new
GetControlsConstantsCompletedEventHandler(backendS ervice_GetControlsConstantsCompleted);
backendService.GetControlsConstantsAsync(1);
backendService.GetContestIdByCodeCompleted += new
GetContestIdByCodeCompletedEventHandler(backendSer vice_GetContestIdByCodeCompleted);

backendService.GetContestIdByCodeAsync((string)Req uest.QueryString["contest"], 1);
backendService.GetLanguageIdByCodeCompleted += new
GetLanguageIdByCodeCompletedEventHandler(backendSe rvice_GetLanguageIdByCodeCompleted);

backendService.GetLanguageIdByCodeAsync((string)Re quest.QueryString["language"], 1);

((string)Request.QueryString["language"]);

while (!(languageReady && contestReady
&&usercontrolsReady))
{ }
Session["BackendContestData"] =
backendService.GetPublicContestData((int)Session["ContestId"]);
backendContestData =
(PublicContestData)(Session["BackendContestData"]);

So I have 3 web services methods which are called async, and I want to wait
until I get the response from all the 3 of them (I set the bool values to
true in the event handler for the completion of the web service methods). As
you can see all 3 methods are called with the same unique user state (1) and
if I do this I get the error inside the event handlers. If I set each method
a different unique user state (1, 2, 3 for example) then my events are not
fired.

Reply With Quote
  #4  
Old   
John Saunders [MVP]
 
Posts: n/a

Default Re: Async web service methods calls - 10-22-2007 , 08:36 PM



"Stefan Filip" <StefanFilip (AT) discussions (DOT) microsoft.com> wrote

Quote:
Thanks for answering John, but I already did that. Here's how my code
looks
like:

languageReady = false;
contestReady = false;
usercontrolsReady = false;

backendService.GetControlsConstantsCompleted += new
GetControlsConstantsCompletedEventHandler(backendS ervice_GetControlsConstantsCompleted);
backendService.GetControlsConstantsAsync(1);
backendService.GetContestIdByCodeCompleted += new
GetContestIdByCodeCompletedEventHandler(backendSer vice_GetContestIdByCodeCompleted);

backendService.GetContestIdByCodeAsync((string)Req uest.QueryString["contest"],
1);
backendService.GetLanguageIdByCodeCompleted += new
GetLanguageIdByCodeCompletedEventHandler(backendSe rvice_GetLanguageIdByCodeCompleted);

backendService.GetLanguageIdByCodeAsync((string)Re quest.QueryString["language"],
1);

((string)Request.QueryString["language"]);

while (!(languageReady && contestReady
&&usercontrolsReady))
{ }
Session["BackendContestData"] =
backendService.GetPublicContestData((int)Session["ContestId"]);
backendContestData =
(PublicContestData)(Session["BackendContestData"]);

So I have 3 web services methods which are called async, and I want to
wait
until I get the response from all the 3 of them (I set the bool values to
true in the event handler for the completion of the web service methods).
As
you can see all 3 methods are called with the same unique user state (1)
and
if I do this I get the error inside the event handlers. If I set each
method
a different unique user state (1, 2, 3 for example) then my events are not
fired.
Sorry for not following up sooner, but aren't you the poster who got an
error complaining that you can't use the same state in multiple calls? Yet
here, you're telling me that you use the same state, and you get an error.
What did I miss?

What happens if you try something like:

object state1 = 1;
object state2 = 1;
object state3 = 1;

and pass state1, etc. as the state?

Perhaps you're not really passing the number 1? Are you passing some other
value type?
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer




Reply With Quote
  #5  
Old   
Stefan Filip
 
Posts: n/a

Default Re: Async web service methods calls - 10-23-2007 , 07:09 AM



Hi,

I finally realised what was going on. The problem was that the events were
not invoked because I was in an infinite loop (the while) and I didn't
realise that I was on the same thread, so the events could not be invoked.
Thanks anyway for your replies and sorry for loosing your time with this .

"John Saunders [MVP]" wrote:

Quote:
"Stefan Filip" <StefanFilip (AT) discussions (DOT) microsoft.com> wrote in message
news:6CD5CF8F-E949-4A6C-809C-878710D981B6 (AT) microsoft (DOT) com...
Thanks for answering John, but I already did that. Here's how my code
looks
like:

languageReady = false;
contestReady = false;
usercontrolsReady = false;

backendService.GetControlsConstantsCompleted += new
GetControlsConstantsCompletedEventHandler(backendS ervice_GetControlsConstantsCompleted);
backendService.GetControlsConstantsAsync(1);
backendService.GetContestIdByCodeCompleted += new
GetContestIdByCodeCompletedEventHandler(backendSer vice_GetContestIdByCodeCompleted);

backendService.GetContestIdByCodeAsync((string)Req uest.QueryString["contest"],
1);
backendService.GetLanguageIdByCodeCompleted += new
GetLanguageIdByCodeCompletedEventHandler(backendSe rvice_GetLanguageIdByCodeCompleted);

backendService.GetLanguageIdByCodeAsync((string)Re quest.QueryString["language"],
1);

((string)Request.QueryString["language"]);

while (!(languageReady && contestReady
&&usercontrolsReady))
{ }
Session["BackendContestData"] =
backendService.GetPublicContestData((int)Session["ContestId"]);
backendContestData =
(PublicContestData)(Session["BackendContestData"]);

So I have 3 web services methods which are called async, and I want to
wait
until I get the response from all the 3 of them (I set the bool values to
true in the event handler for the completion of the web service methods).
As
you can see all 3 methods are called with the same unique user state (1)
and
if I do this I get the error inside the event handlers. If I set each
method
a different unique user state (1, 2, 3 for example) then my events are not
fired.

Sorry for not following up sooner, but aren't you the poster who got an
error complaining that you can't use the same state in multiple calls? Yet
here, you're telling me that you use the same state, and you get an error.
What did I miss?

What happens if you try something like:

object state1 = 1;
object state2 = 1;
object state3 = 1;

and pass state1, etc. as the state?

Perhaps you're not really passing the number 1? Are you passing some other
value type?
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer




Reply With Quote
  #6  
Old   
Rolf
 
Posts: n/a

Default RE: Async web service methods calls - 12-17-2007 , 01:38 PM




Quote:
Hello,

I'm trying to launch several async calls for different methods of a web
service, but I get this error when i'm trying to read the result (There was
an error during asynchronous processing. Unique state object is required for
multiple asynchronous simultaneous operations to be outstanding.). I read the
post at
http://forums.microsoft.com/MSDN/Sho...79895&SiteID=1, and I
get the same error, but I have async calls to different web service methods.
What should I do?
Thanks
class Program
{
static void Main(string[] args)
{
s.UseDefaultCredentials = true;
s.UnsafeAuthenticatedConnectionSharing = true;

ParameterizedThreadStart p = new ParameterizedThreadStart(Call);
Thread t = new Thread(p);
t.SetApartmentState(ApartmentState.STA);
t.Start(0);

Console.ReadLine();
}

static NLBService.NLBService s = new ConsoleApplication1.NLBService.NLBService();

static void Call(object o)
{
s.HelloWorldCompleted += new ConsoleApplication1.NLBService.HelloWorldCompleted EventHandler(s_HelloWorldCompleted);
s.HelloWorldAsync();
}

static void s_HelloWorldCompleted(object sender, ConsoleApplication1.NLBService.HelloWorldCompleted EventArgs e)
{
if (e.Error == null)
{
Console.WriteLine("ok");
}
else
{
Console.WriteLine("error");
}
}
}

Why does not this work?
If I want to use it synchronous it works fine, but I can not figure out, how to call a web service asynchronous from a thread that is different from the working thread.

Thank You

BizTalk Utilities - Frustration free BizTalk Adapters
http://www.topxml.com/biztalkutilities


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.