RE: Async web service methods calls

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




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?
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.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
http://www.topxml.com/biztalkutilities
.



Relevant Pages