all groups > dotnet web services > october 2007 >
You're in the

dotnet web services

group:

Async web service methods calls



Async web service methods calls Stefan Filip
10/17/2007 7:20:00 AM
dotnet web services: 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/ShowPost.aspx?PostID=2279895&SiteID=1, and I
get the same error, but I have async calls to different web service methods.
What should I do?
Re: Async web service methods calls John Saunders [MVP]
10/17/2007 11:56:54 AM
[quoted text, click to view]

You should use a unique state object. It's not a per-method. Thing.

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

Re: Async web service methods calls Stefan Filip
10/18/2007 1:16:01 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(backendService_GetControlsConstantsCompleted);
backendService.GetControlsConstantsAsync(1);
backendService.GetContestIdByCodeCompleted += new
GetContestIdByCodeCompletedEventHandler(backendService_GetContestIdByCodeCompleted);

backendService.GetContestIdByCodeAsync((string)Request.QueryString["contest"], 1);
backendService.GetLanguageIdByCodeCompleted += new
GetLanguageIdByCodeCompletedEventHandler(backendService_GetLanguageIdByCodeCompleted);

backendService.GetLanguageIdByCodeAsync((string)Request.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
Re: Async web service methods calls John Saunders [MVP]
10/22/2007 8:36:57 PM
[quoted text, click to view]

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

Re: Async web service methods calls Stefan Filip
10/23/2007 4:09:00 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 :).

[quoted text, click to view]
RE: Async web service methods calls Rolf
12/17/2007 6:38:18 PM

[quoted text, click to view]

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.HelloWorldCompletedEventHandler(s_HelloWorldCompleted);
s.HelloWorldAsync();
}

static void s_HelloWorldCompleted(object sender, ConsoleApplication1.NLBService.HelloWorldCompletedEventArgs 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
AddThis Social Bookmark Button