Over the past week I have been planning to launch the first open to
public Service Broker. At the same time, my dev team was having a
discussion regarding how we can do something cool and interesting to
get the community involved in our product. So I decided to setup simple
services on my public Service Broker to let people tinker around with
it. This is the zeroth in a series of BrokerChalleges; zero since it
requires hardly any skill, just the motivation to play with cool
My service broker endpoint is hosted at the location tcp://rushi.desai.name:4022 and uses certificate based authentication with this certificate identity (public key)
and supports AES encryption. In this challenge you will have to attempt
to setup your own endpoint and then send a message to the CommentService hosted by my broker at this endpoint. If you are successful, your comment will appear here:
[I wanted to embed an IFRAME object here but CommunityServer::Blogs would not let me!]
I am not going to provide any T-SQL snippets here and you will have
to figure that out yourself by referring to the documentation (Books
- Install SQL Server 2005 June CTP: While it should work with
the April CTP as well, I haven't tested it. If you want to upgrade or
if you don't have a SQL Server on your box, you can download the brand new CTP from here.
- Create a Service Broker endpoint: Next step is to
create a service broker endpoint. The endpoint listens for incoming TCP
connections on the port you specify (default is 4022). It should use certificate authentication and you will require to create a certifcate for owner dbo in master.
If you have a firewall, you may need to punch a hole in that. My
endpoint supports only AES encryption, so if you make encryption
'required', make sure to use AES as well.
- Grant access to my SQL Server instance to connect to yours:
Next you will have to grant access to my SQL Server instance to connect
to your endpoint. You can do that be granting connect permission on the
endpoint to public, or by creating a login and user in master, adding this certificate to that user and granting connect permission on your endpoint to that user.
- Create a database: Create a new database (or use a
pre-existing one with broker enabled). Create a database master key so
that you can use secure dialogs in the future. We will not be doing
- Create service broker objects: You will need to
create a queue and then create the initiating service on this queue in
your new database. You will use this service to begin a dialog with my 'CommentService'
service and send a message. In order for acknowledgments and reply
messages to get back, my Service Broker will require a route to your
service. But since I do not know that in advance, you should use a
fully-qualified URL as your service name (eg> [tcp://myhost.microsoft.com:4022/CommentClient]). The 'CommentService' serves the [http://rushi.desai.name/public/PostCommentContract] which you must use to post your comments. This contract consists of just one message type, namely [http://rushi.desai.name/public/AddCommentMessage] which is sent by initiator. This message type only accepts valid XML that conforms with the following schema: (Don't worry, e-mail address is for my reference and won't be published)
<?xml version="1.0" encoding="utf-8"?> <xs:schema elementFormDefault="qualified"
<xs:element name="senderName" type="xs:string"
minOccurs="1" maxOccurs="1" />
<xs:element name="emailAddress" type="xs:string"
maxOccurs="1" minOccurs="1" />
<xs:element name="body" type="xs:string"
maxOccurs="1" minOccurs="0" />
- Create a route to the 'CommentService': Finally you need a route that tells your broker how to get to 'CommentService'. You know the address of my endpoint so this should be fairly straightforward.
- Setup dialog security: I'll relieve you off this for now by turning off dialog security.
- Now lets start talking: At this point you are done with
all the DDL steps. It's time to fire off some DML. Begin a dialog from
your newly created service to the 'CommentService' on the [http://rushi.desai.name/public/PostCommentContract]. And send a message of type [http://rushi.desai.name/public/AddCommentMessage] with a well-formed valid message body. You can briefly describe yourself in the message body.
<body>Hi! I am a developer in the Service Broker team. Since
there was no disclaimer that team members cannot participate in
the BrokerChallenges, I took the opportunity of making myself famous by
sending this message.</body>
When I get the message, it will activate a stored proc which
receives the message, adds the comment to a table and ends the
conversation. Entries from the table is displayed in the hall of fame
link. If you successfully send me a message and I receive it, you will
get an EndDialog message in your initiator queue. If you don't, check
sys.transmission_queue to see if the comment message is still stuck
there and what is the reason for that. You could also look at ERRORLOG
and the NT event log for clues. You can ask questions in the comments