Example #1
0
        private IAsyncResult BeginMessageInternal(MessageBase message, AsyncCallback storedCallback, object asyncState, AsyncCallback callback)
        {
            byte[]             body;
            WebRequest         request       = message.Encode(out body);
            PortMapAsyncResult mappingResult = PortMapAsyncResult.Create(message, request, storedCallback, asyncState);

            if (body.Length > 0)
            {
                request.ContentLength = body.Length;
                request.BeginGetRequestStream(delegate(IAsyncResult result) {
                    try
                    {
                        Stream s = request.EndGetRequestStream(result);
                        s.Write(body, 0, body.Length);
                        request.BeginGetResponse(callback, mappingResult);
                    }
                    catch (Exception ex)
                    {
                        mappingResult.Complete(ex);
                    }
                }, null);
            }
            else
            {
                request.BeginGetResponse(callback, mappingResult);
            }
            return(mappingResult);
        }
        private void CompleteMessage(IAsyncResult result)
        {
            PortMapAsyncResult mappingResult = result.AsyncState as PortMapAsyncResult;

            mappingResult.CompletedSynchronously = result.CompletedSynchronously;
            mappingResult.Complete();
        }