public Guid BeginNewConversation(Guid conversationGroupId, TimeSpan timeout) { ThrowIfDisposedOrNotOpen(); endConversationOnClose = false; //if a conversation is explicitly started, don't automatically close it. TimeoutHelper helper = new TimeoutHelper(timeout); try { string SQL = string.Format( @"BEGIN DIALOG CONVERSATION @ConversationHandle FROM SERVICE @Source TO SERVICE @Target ON CONTRACT [{0}] WITH ENCRYPTION = {1}", contract, useEncryption?"ON":"OFF"); if (conversationGroupId != Guid.Empty) { SQL += String.Format(", RELATED_CONVERSATION_GROUP = '{0}'", conversationGroupId); } SqlCommand cmd = new SqlCommand(SQL, con); cmd.CommandTimeout = helper.RemainingTimeInMillisecondsOrZero(); SqlParameter pconversationHandle = cmd.Parameters.Add("@ConversationHandle", SqlDbType.UniqueIdentifier); pconversationHandle.Direction = ParameterDirection.Output; SqlParameter pTarget = cmd.Parameters.Add("@Target", SqlDbType.VarChar); pTarget.Value = this.target; SqlParameter pSource = cmd.Parameters.Add("@Source", SqlDbType.VarChar); pSource.Value = this.source; cmd.ExecuteNonQuery(); this.conversation = SsbHelper.GetConversationInfo((Guid)pconversationHandle.Value, con); return(this.conversation.ConversationHandle); } catch (SqlException ex) { if (!helper.IsTimeRemaining) { throw new TimeoutException(String.Format("Timed out while beginning new conversation to service {0}. Timeout value was {1} seconds", this.target, timeout.TotalSeconds), ex); } else { throw new CommunicationException(String.Format("An exception occurred while beginning new conversation to service {0}", this.target), ex); } } finally { } }
public void OpenConversation(Guid conversationHandle, TimeSpan timeout) { ThrowIfDisposedOrNotOpen(); this.conversation = SsbHelper.GetConversationInfo(conversationHandle, con); }