Back to list
Views:   0
Replies:  0
Archived
,
Reply 1
Below is some code that shows a rudimentary solution. It works in a console application, for a true UI you will need do do more, e.g. marshal the callback event to the UI thread.

The attached "SoaAsync.zip" file also contains a quick WPF application.

class ClientArgs : EventArgs
    {
        public Reply Reply { get; set; }
    }

    class Request
    {
        public string Input;
    }

    class Reply
    {
        public string Output;
    }

    class Client
    {
        public delegate void CallCompletedDel(object sender, ClientArgs args);

        public event CallCompletedDel CallCompletedEvent;

        public void RequestAsync(Request req)
        {
            if( null != CallCompletedEvent)
            {
                ClientArgs args = new ClientArgs();
                args.Reply = new Reply();
                args.Reply.Output = req.Input + " Output";

                // this will actually go to the Web Services as an async call
                CallCompletedEvent.BeginInvoke(this, args, null, null);  
            }
        }
    }

then you uses it in the following way

            ManualResetEvent block = new ManualResetEvent(false);
            bool _isAsyncDone = false;
            Reply reply = null;
            int _timeout = 1000;

            Client client = new Client();
            
            client.CallCompletedEvent += (sender, e) =>
            {
                if( null != e)
                {
                    reply = e.Reply;
                    _isAsyncDone = true; 
                    block.Set(); 
                }
            };


            Request req = new Request();
            req.Input = "Input";
            client.RequestAsync(req);

            block.WaitOne(_timeout, false);

            if (false == _isAsyncDone)
            {
                Console.WriteLine("Test took too long");
            }
            else
            {
                Console.WriteLine(reply != null ? reply.Output : "Reply is null");
            }

 
Danut Prisacau, Aug 19, 2011
Thanks a lot for your response.
Mar 17, 2011
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas