/*
  Setup script for database 2 for SSB sample communicating
  between two local databases.

  Run this script to set up the necessary objects for
  SSB communication.

  Any questions etc.: nielsb@develop.com

*/

USE master;
go

--Create the second database, TRUSTWORTHY needs to be ON
--if communicating between databases without CERTIFICATES
CREATE DATABASE [loc_ssb2]
WITH TRUSTWORTHY ON;
go

use [loc_ssb2];
go

--create a master db key, necessary when starting  a dialog
CREATE MASTER KEY 
ENCRYPTION BY PASSWORD = 'hello2';
go


--having created the database, we can now start creating
--the SSB objects

-- we need two message types - they are the same
-- as in ssb1
CREATE MESSAGE TYPE [sendmsg]
VALIDATION = WELL_FORMED_XML;

CREATE MESSAGE TYPE [recmsg]
VALIDATION = WELL_FORMED_XML;
go

--create the message contract - looks the same as in SSB1
--and define who sends what
CREATE CONTRACT [Ctract]
(
  [sendmsg]
  sent by initiator,
  [recmsg]
  sent by target
);
go

--create the queue, at this stage we do not care
--about activation. Different name than SSB1 (not necessary
--but easier to see what happens)
CREATE QUEUE q2
with status = ON;
go

--finally we need a service. Here we need a different name
--than SSB1, otherwise weird things can happen
CREATE SERVICE s2
on queue q2
(
  [Ctract]
);
go

--now you ar ready to do the fun work, go to Step 1 in the
--script file 2_communicate_db1.sql

