-- This works, i.e. defined message type an contract
use scratch

ALTER DATABASE scratch
SET ENABLE_BROKER
GO
ALTER DATABASE scratch
SET RECOVERY SIMPLE
GO

Create QUEUE simpleQ

CREATE MESSAGE TYPE M1 VALIDATION=None

CREATE CONTRACT C1 (M1 SENT BY ANY)


CREATE 
--DROP
SERVICE S1 ON QUEUE simpleQ
(C1)


Create QUEUE simpleQ2

CREATE 
--DROP
SERVICE S2 ON QUEUE simpleQ2
(C1)

CREATE 
--ALTER
PROC SendMessage2(@msg XML)
AS
BEGIN TRAN
DECLARE @conv UNIQUEIDENTIFIER
BEGIN DIALOG CONVERSATION @conv
FROM SERVICE [S1]
TO SERVICE 'S2'
ON CONTRACT C1
WITH ENCRYPTION = OFF;
SELECT @conv;
SEND ON CONVERSATION @conv
Message Type M1
(@msg)
COMMIT TRAN


SendMessage2 '<test/>'


select CAST(message_body as XML) from simpleQ2


-- this does not work, i.e. using default message and contract

CREATE QUEUE DefQ1
CREATE SERVICE DefS1 ON QUEUE DefQ1


CREATE QUEUE DefQ2
CREATE SERVICE DefS2 ON QUEUE DefQ2


CREATE 
--ALTER
PROC SendDefMessage(@msg XML)
AS
BEGIN TRAN
DECLARE @conv UNIQUEIDENTIFIER
BEGIN DIALOG CONVERSATION @conv
FROM SERVICE DefS1
TO SERVICE 'DefS2'
WITH ENCRYPTION = OFF;
SELECT @conv;
SEND ON CONVERSATION @conv
(@msg)
COMMIT TRAN

SendDefMessage '<test/>'

select * from DefQ1
select CAST(message_body as XML) from DefQ1

-- this produces
/*
<Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error">
<Code>-8425</Code>
<Description>The service contract 'DEFAULT' is not found.</Description>
</Error>
*/


