/*
  Setup script for server 2 database 2 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_ssb2];
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 q2
with status = ON;
go

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

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

--as we'll be doing encrypted dialogs we need a remote service binding
--and the user is the user we created in the 2_setup_objects_server2_db.sql scripts
CREATE REMOTE SERVICE BINDING [myRms]
TO SERVICE 'rem_s1' 
WITH  USER = remdlguser2,
ANONYMOUS=Off
go

--give the user send rights on the service
grant send on service::rem_s2 to remdlguser2;
go

--we're now ready to test it out
--go back to server 1 and the script 4_begindlg_server1_db.sql
