Example #1
0
            private bool CompleteReadUpgradeResponse()
            {
                int count = this.connection.EndRead();

                if (!ConnectionUpgradeHelper.ValidateUpgradeResponse(this.connection.AsyncReadBuffer, count, this.decoder))
                {
                    if (onFailedUpgrade == null)
                    {
                        onFailedUpgrade = Fx.ThunkCallback(new AsyncCallback(ConnectionUpgradeHelper.InitiateUpgradeAsyncResult.OnFailedUpgrade));
                    }
                    IAsyncResult result = ConnectionUpgradeHelper.BeginDecodeFramingFault(this.decoder, this.connection, this.remoteAddress.Uri, this.contentType, ref this.timeoutHelper, onFailedUpgrade, this);
                    if (result.CompletedSynchronously)
                    {
                        ConnectionUpgradeHelper.EndDecodeFramingFault(result);
                    }
                    return(result.CompletedSynchronously);
                }
                this.connectionStream = new ConnectionStream(this.connection, this.defaultTimeouts);
                IAsyncResult result2 = null;
                WindowsImpersonationContext context = (this.identityToImpersonate == null) ? null : this.identityToImpersonate.Impersonate();

                try
                {
                    using (context)
                    {
                        result2 = this.upgradeInitiator.BeginInitiateUpgrade(this.connectionStream, onInitiateUpgrade, this);
                    }
                }
                catch
                {
                    throw;
                }
                if (!result2.CompletedSynchronously)
                {
                    return(false);
                }
                this.CompleteUpgrade(result2);
                return(true);
            }