/*
  Setup script for database 1 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 first database, TRUSTWORTHY needs to be ON
--if communicating between databases without CERTIFICATES
CREATE DATABASE [loc_ssb1]
WITH TRUSTWORTHY ON;
go

use [loc_ssb1];
go

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


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

-- we need two message types
CREATE MESSAGE TYPE [sendmsg]
VALIDATION = WELL_FORMED_XML;

CREATE MESSAGE TYPE [recmsg]
VALIDATION = WELL_FORMED_XML;
go

--create the message contract
--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
CREATE QUEUE q1
with status = ON;
go

--finally we need a service
CREATE SERVICE s1
on queue q1
(
  [Ctract]
);
go

--we now have all objects in the first database
--run the script 1_setup_db2.sql to create the objects
--in the second database