/*
  Script for database 1 for SSB sample, communicating
  between two local databases.

  This script starts a conversation and sends a message
  to the service in the other database.

  Any questions etc.: nielsb@develop.com

*/

--STEP 1
--don't forget to run this
use [loc_ssb1];
go

----start the dialog and send a message
----uncomment from here until the following go statement and run
--DECLARE @h uniqueidentifier --conversation handle
--DECLARE @msg xml; --will hold the message
--
--BEGIN DIALOG CONVERSATION @h
--FROM SERVICE s1
--TO SERVICE 's2'
--ON CONTRACT [Ctract];
--
--SET @msg = '<hello/>';
--SEND ON CONVERSATION @h
--MESSAGE TYPE [sendmsg]
--(@msg);
--
----check that the message is not in the tx queue
--SELECT * from sys.transmission_queue
--if(@@rowcount > 0)
--  print 'something is not right, check the tx queue'
--
----check if we have received an error in s1's queue
--SELECT * from q1
--if(@@rowcount > 0)
--  print 'An error has happened. Check the queue'
--
--go


--go now to Step 2 in the script 2_communicate_db2.sql 
--to receive the message and send a message back


--Step 5
----you have now been over in the ssb2 db and received and
----sent a message back. In the "real world" you'd probably
----now read off the message from the queue and do something with it
----here we just select from the queue and end and cleanup. 
----There shoudl be two messages in the queue, one which was 
----sent from service s2 and one about the conversation ending. 
----uncomment from here to go and run

--select * from q1;
--
--declare @h uniqueidentifier;
--select top(1) @h = conversation_handle
--from q1;
--
--end conversation @h
--with cleanup;
--go

--go now to Step 6 in the script 3_activation_db2.sql to
--set up activation on the queue

--Step 9
--the activation procedure has now been set-up
--it's time to test it, we'll use the same syntax as
--when we first sent a message

--start the dialog and send a message
--uncomment from here until the following go statement and run
--DECLARE @h uniqueidentifier --conversation handle
--DECLARE @msg xml; --will hold the message
--
--BEGIN DIALOG CONVERSATION @h
--FROM SERVICE s1
--TO SERVICE 's2'
--ON CONTRACT [Ctract];
--
--SET @msg = '<hello/>';
--SEND ON CONVERSATION @h
--MESSAGE TYPE [sendmsg]
--(@msg);
--go

--Step 10
-- check that we have recieved the message (there should be
--two messages in the queue; the message sent back plus an END
--CONVERSATION message
--uncomment from here to go and run
--select * from q1;
--go

--Step 11
-- close down the conversation, we use the same syntax as in Step 5
-- uncomment from here and execute
--declare @h uniqueidentifier;
--select top(1) @h = conversation_handle
--from q1;
--
--end conversation @h
--with cleanup;
--go

--finally go to Step 12 in 3_activation_db2.sql and see that you have
--a message in the audit table








