Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Other Technologies / Service Broker / July 2008

Tip: Looking for answers? Try searching our database.

mystified over source of Hello World! text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dwight Johnson - 14 Jul 2008 15:32 GMT
I recently installed the sample code, HelloWorld_CLR and got it
working. What I cannot figure out is where the actual text "Hello
World!" is coming from! When I do a search for that text throughout
the solution and the t-sql code, it only appears in the
HelloWorldService code, in a method called SayHello, which is never
called.

So, can anyone help me understand where the text in the dialog is
coming from? I am completely baffled.
Bob Beauchemin - 15 Jul 2008 01:33 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.