
USE SodaDB
GO

IF EXISTS (SELECT * FROM sys.services WHERE name = 'InvService_L9A')
    DROP SERVICE InvService_L9A;
GO
IF EXISTS 
  (SELECT * FROM sys.service_queues WHERE name = 'InvRequestQueue_L9A')
    DROP QUEUE InvRequestQueue_L9A;
GO

IF EXISTS (SELECT * FROM sys.services WHERE name = 'InvInitiator_L9A')
    DROP SERVICE InvInitiator_L9A;
GO

IF EXISTS 
  (SELECT * FROM sys.service_queues WHERE name = 'InvResponseQueue_L9A')
    DROP QUEUE InvResponseQueue_L9A;
GO

IF EXISTS 
  (SELECT * FROM sys.service_contracts WHERE name = 'InvContract_L9A')
    DROP CONTRACT InvContract_L9A;
GO

IF EXISTS 
  (SELECT * FROM sys.service_message_types WHERE name = 'InvRequestMsg_L9A')
    DROP MESSAGE TYPE InvRequestMsg_L9A;
GO

IF EXISTS 
  (SELECT * FROM sys.service_message_types WHERE name = 'InvResponseMsg_L9A')
    DROP MESSAGE TYPE InvResponseMsg_L9A;
GO


-- 
-- CREATE the MESSAGE TYPES and CONTRACT for this program
-- CREATE the QUEUES and SERVICES for this program
--

-- define two message types with XML validation
CREATE MESSAGE TYPE InvRequestMsg_L9A 
VALIDATION = VALID_XML WITH SCHEMA COLLECTION dbo.InventoryReq_xsd
GO

CREATE MESSAGE TYPE InvResponseMsg_L9A
VALIDATION = VALID_XML WITH SCHEMA COLLECTION dbo.InventoryReq_xsd
GO

-- define a contract between the two sides
CREATE CONTRACT InvContract_L9A
 (InvRequestMsg_L9A SENT BY INITIATOR,
  InvResponseMsg_L9A SENT BY TARGET)
GO

-- create queues and services
CREATE QUEUE InvRequestQueue_L9A
GO

CREATE QUEUE InvResponseQueue_L9A
GO

CREATE SERVICE InvService_L9A
 ON QUEUE InvRequestQueue_L9A
 (InvContract_L9A)
GO

CREATE SERVICE InvInitiator_L9A
 ON QUEUE InvResponseQueue_L9A
 (InvContract_L9A)
GO

