-- This lives on the remote instance
--

USE BrokerDB2
GO

-- 
-- Step 2-Certs: Create a certificate for dialog encryption
-- This will be used to represent your service user in the other databasse
--


CREATE CERTIFICATE cert2
with subject = 'cert2',
start_date = '09/01/2005'
active for begin_dialog = on;
go

--
-- Back the certificate up to a file
-- This only backs up the public key, not the private key
--
BACKUP CERTIFICATE cert2
TO FILE = 'c:\certs\cert2.cer'
GO

--
-- Step 4-Certs:
-- Create a user in this database (without login or any other priv)
--
CREATE USER user2 WITHOUT LOGIN
GO

CREATE CERTIFICATE cert1_remote
AUTHORIZATION user2
FROM FILE = 'c:\certs\cert1.cer'
GO

-- we need this if:
-- 1. trustworthy is off in the other database
-- 2. the other database has a binding that uses the cert
-- 3. the binding specifies ANONYMOUS = OFF
grant send on service::InvService to user2;
go

-- we need this if:
-- 1. trustworthy is off in the other database
-- 2. the other database has a binding that uses the cert
-- 3. the binding specifies ANONYMOUS = ON
grant send on service::InvService to public;
go

--
-- we don't need a remote service binding in this case
-- these are only required at the initiator
--

select * from sys.remote_service_bindings