-- This lives on the remote instance
--

IF EXISTS
  (SELECT * FROM sys.databases WHERE name = 'BrokerDB2')
DROP DATABASE BrokerDB2
GO

CREATE DATABASE BrokerDB2
GO

USE BrokerDB2
GO

-- Step 2: Create objects in database 2
-- Message Types And Contracts Go On Both Sides

-- define two message types with XML validation
CREATE MESSAGE TYPE InvRequestMsg 
VALIDATION = WELL_FORMED_XML
GO

CREATE MESSAGE TYPE InvResponseMsg
VALIDATION = WELL_FORMED_XML
GO

-- define a contract between the two sides
CREATE CONTRACT InvContract
 (InvRequestMsg SENT BY INITIATOR,
  InvResponseMsg SENT BY TARGET)
GO

-- create queues and services
CREATE QUEUE InvRequestQueue
GO

CREATE SERVICE InvService
 ON QUEUE InvRequestQueue
 (InvContract)
GO

---
--- security portion
--- Create master key. 
---

CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'StrongPW1'
GO

---
--- End of Step 2
---


