By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,153 Members | 970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,153 IT Pros & Developers. It's quick & easy.

Async web service methods calls

P: n/a
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
Oct 17 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Stefan Filip" <St*********@discussions.microsoft.comwrote in message
news:E2**********************************@microsof t.com...
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
Oct 17 '07 #2

P: n/a
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.
Oct 18 '07 #3

P: n/a
"Stefan Filip" <St*********@discussions.microsoft.comwrote in message
news:6C**********************************@microsof t.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
Oct 23 '07 #4

P: n/a
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:
"Stefan Filip" <St*********@discussions.microsoft.comwrote in message
news:6C**********************************@microsof t.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
Oct 23 '07 #5

P: n/a
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
Dec 17 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.