/*
  Setup script for server 1 database 1 for SSB sample communicating
  between two remote servers

  Run this script to set up SSB objects and finalize dialog security 
  through Remote Service Bindings. Most of this script is taken from
  the LocalSample scripts.

  Any questions etc.: nielsb@develop.com

*/

--Step 1

use [rem_ssb1];
go

-- 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

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

--create a route to the remote service, we know it'll be called rem_s2
create route [rem_s2_route]
with
service_name = 'rem_s2',
address = 'TCP://192.168.13.110:4022';
go

select * from sys.routes

--as we'll be doing encrypted dialogs we need a remote service bindin
CREATE REMOTE SERVICE BINDING [myRms]
TO SERVICE 'rem_s2' 
WITH  USER = remdlguser1,
ANONYMOUS=Off

--give the user send rights on the service
grant send on service::rem_s1 to remdlguser1;
go


--go now to remote server and the script file 3_setup_ssb_server2_db.sql
