Hi Dwight,
This example (in the DDL) defines two services HelloWorldService and
HelloWorldClient. When a message arrives at the queue corresponding to
HelloWorldService (that's ServiceQueue in the DDL) the stored procedure that
corresponds to the .NET method ServiceProc in the HelloWorldService.cs or
HelloWorldService.vb code. So its HelloWorldService's static method
ServiceProc() that is being called.
The first thing ServiceProc does is to create an instance of the
HelloWorldService class. Then it calls the HelloWorldService's Run method.
This method is available because HelloWorldService inherits from the class
Microsoft.Samples.SqlServer.Service class. The code for this class can be
found in the examples directory "ServiceBrokerInterface".
The Run method reads a message from the queue when one is available and
dispatches the message (in the DispatchMessage method using Invoke) to the
method in the HelloWorldService class derived class ("your" class) that
contains the attribute (.NET attribute) named BrokerMethod. The BrokerMethod
attribute "names" a message and message contract (in this case, "Request"
message and "Greeting" contract).
Put a little bit more simply, when a message arrives, a dispatcher in the
base class looks at an array of contract, message, method names and
dispatches the message to one method name that matches contract and message.
So that's how "SayHello" is called.
The thing that makes the sample non-intuitive is that the attribute
[BrokerMethod("Greeting", "Request")] in the code is pretty well hidden
because of the gratuitous SuppressMessage attributes. Scroll to the right on
the line with SuppressMessage to see the most important attribute on the
line!!
Hope this helps, write back if it doesn't,
Bob Beauchemin
SQLskills
>I recently installed the sample code, HelloWorld_CLR and got it
> working. What I cannot figure out is where the actual text "Hello
[quoted text clipped - 5 lines]
> So, can anyone help me understand where the text in the dialog is
> coming from? I am completely baffled.
Dwight Johnson - 15 Jul 2008 14:23 GMT
Bob,
Thanks for the wonderfully clear explanation. But I am not there yet.
I deleted the HelloWorldService.dll, changed the text in SayHello from
"Hello World!" to "Hello Dwight!", rebuilt, and reran. It still says
"Hello World!". Do I need to drop and recreate the Assembly in SQL
Server to get the new text?
And you say the SuppressMessage attributes are gratuitous. What effect
would there be in leaving them out?
Thanks,
Dwight
Dwight Johnson - 15 Jul 2008 14:59 GMT
Bob,
I did some testing and answered my questions.
The Assembly is a copy of the dll, not a pointer to the file location,
so it is necessary to drop the procedure and assembly and recreate
both when the dll changes.
Also, I moved the BrokerMethod attribute to the left, making it more
visible, and then later deleted the SuppressMessage attributes on
SayHello. No obvious difference in the way it ran.
Dwight
Bob Beauchemin - 15 Jul 2008 22:43 GMT
Hi Dwight,
Glad you enjoyed it. You're correct on all the further points you've made.
I think those attributes override rules when using the utility FxCop.
Cheers,
Bob
> Bob,
>
[quoted text clipped - 9 lines]
>
> Dwight