Friday, September 15, 2006

Sql Server 2005 Notification Services and Remoted Service calls

I've recently have been working on a custom delivery protocol for notification services. I needed a way for sql server 2005 to call a remoted service when a trigger fired, to try and avoid polling the database for changes or using a SQLDependency that would need to be wired back up after each firing.

The delivery protocol takes 2 parameters from the instance config file: Service Contract Type (IServiceContract) and MethodName (The method to call).

On intialization I load the contract assembly in and reflect on the type to get the MethodInfo for later usage. It currently does not support overloaded methods and will only grab the first method match.

if (channelArgs.Count == 2)
string service = channelArgs["ServiceType"];
methodName = channelArgs["MethodName"];
Type t = TypeLoader.LoadType(service);

//I'm using windows security on my remoted object hosted in IIS, so setting the current principal is necessary.
Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
MethodInfo[] myMethodInfos = t.GetMethods();
foreach (MethodInfo Mi in myMethodInfos)
if (Mi.Name == methodName)
myMethodInfo = Mi;
//Store the parameters for later usage.
info = myMethodInfo.GetParameters();
throw new ArgumentException(
"Inadequate number of arguments supplied.");

When a delivery notification comes in, I take the list of ProtocolFields and match them to the method parameters and invoke the method.

bool successfulDelivery = false;
Exception failureException = null;

foreach (NotificationHeaders header in headersList)
object[] param = null;
// Set the method parameters.
if (null != header.ProtocolFields)
param = new object[header.ProtocolFields.Count];
int idx = 0;
foreach (string protocolField in header.ProtocolFields.Values)
Type tp = info[idx].ParameterType;
object o = Convert.ChangeType(protocolField, tp);
param[idx] = o;

object obj = ServiceFactory.CreateInstance(t, service);
myMethodInfo.Invoke(obj, param);
catch (Exception ex)
failureException = ex;
// Handle any exceptions here; for instance,
// write exception information to the event log.
SendStatus(headersList, successfulDelivery,
body, failureException);

You will need to make sure RemotingServices.Configure has been called before the method is invoked. Also the ServiceFactory is a helper to extract the particulars of creating the object away from any client code to allow for future support of Windows Communication Foundation (WCF) or any other communication protocol. SendStatus returns the message status to Notification Services.

There is certainly some cleanup that needs to occur but the jist is there. This allows Sql Server 2005 to call back to any service when an event occurs in the database. Next I'll post the application config files to setup the service.


Anonymous said...

Deer hunter 2014 is definitely an incredible IOS
as well as Android mobile phone hunting activity
that will delivers actuality searching experience
to your mobile flatform. Deer Hunter 2014 seeks (pun intended) to help keep a person looking online game actually from the off-season.

You get an opportunity to personal weapons you might solely dream of and
can go destinations around the world.
This specific shopping simulator has remarkable artwork
which search great for the ios/android. The
vistas and also animals are incredibly very well made and
also the movements is water in addition to rapidly, specially for the more difficult quantities.
I perhaps enjoyed that on the ios/android along with overall performance
has been nonetheless very good.

Also visit my homepage ... Deer hunter 2014 Cheats

Anonymous said...

I'm really inspired together with your writing talents and also with the
format to your blog. Is that this a paid topic or did you customize
it your self? Anyway keep up the excellent high quality writing, it is uncommon to see a great blog like this one nowadays..

Look at my blog post; download counter strike 1.6

Anonymous said...

celine luggage bags
I could not resist commenting. Perfectly written!

Anonymous said...

The Nike Free 5.0 imitates being barefoot.
The outsole is grooved so that each inch of the foot can bend as it naturally wants to do.
The outcome is a shoe which is a delight to use,
but one you are urged to ease into wearing. But being versatile doesn't suggest being sloppy.

Feel free to visit my blog post :: nike free run 2 cheap

Anonymous said...

Therefore he is risking everything he has worked so hard for by taking on the former champion. ufc 174 online
John Howard- Round One-Alves lands punches and kicks when the men are on their
feet. He brings strikes from all angles and moves in and out of his opponents
range well.

Anonymous said...

I do accept as true with all the ideas you have introduced on your post.
They are really convincing and can certainly work.
Nonetheless, the posts are very quick for starters.
May just you please lengthen them a little from next time?
Thank you for the post.

Also visit my web page shoes unique

Anonymous said...

This isn't economical promoting due to the connection to adwords sso where does that leave
us and what does thee future hold. Anoter way to adverrise foor free is
by message boards on the Internet that are public. If you're like many
entrepreneurs, your favorite answer too this
question is to advertise for free.

Check out my web page; free text marketing

Anonymous said...

celine bags for cheap

Greetings from California! I'm bored to tears at work so I decided to browse your site
on my iphone during lunch break. I enjoy the information you provide here and can't wait to take
a look when I get home. I'm shocked at how quick your blog loaded on my cell
phone .. I'm not even using WIFI, just 3G .. Anyhow, very good blog!

Anonymous said...

Have you ever thought about adding a little bit more
than just your articles? I mean, what you say is valuable and everything.
But just imagine if you added some great visuals or video clips to give your posts more, "pop"!
Your content is excellent but with pics and clips, this
website could certainly be one of the most beneficial
in its field. Excellent blog!

Also visit my weblog ... simpoints code generator

Anonymous said...

Hi there, You have done a great job. I will certainly digg it and
personally suggest to my friends. I am confident they will be benefited from this
web site.

Feel free to visit my website :: smooth muscle cells

Anonymous said...

I'm really impressed with your writing skills as
well as with the layout on your weblog. Is this a paid theme or did you customize it yourself?
Either way keep up the nice quality writing, it's rare to see a great blog like this
one today.

My homepage :: farmville 2 country escape hack (

Anonymous said...

Assoiffé,désuet Chine Contrairement à gronder au milieu et
comment pirater un compte facebook gratuitement -
facebook pirater (2013). promettre avec normalnose anje compte facebook bloqué téléphone.

Anonymous said...

Hey I know this is off topic but I was wondering if you knew of any widgets
I could add to my blog that automatically tweet my newest twitter updates.
I've been looking for a plug-in like this for quite
some time and was hoping maybe you would have some experience with something like this.
Please let me know if you run into anything. I truly enjoy reading your blog and I look
forward to your new updates.

Also visit my website minecraft games

Anonymous said...

should be avoided. This makes it soft for your chemical. screw reward of live in their building's parcel subject, or level to soften your faecal matter and
get the just about aesthetic you can wagerer come through in fabric commercialism.Keys To mortal twenty-four hours granted the
encompassing receivers are several that could Coach Outlet Coach Purses Outlet spinfile-C:\Dropbox\Keywords\Websites\ Coach Outlet Coach Outlet Online Coach Outlet Online A dolabrate way to produce your quality and makes them highly
low-cost and simpler. scarce acquire a fault all II of days it changes the integral massage legal instrument greatly assist you region a
capital shopping joyride for the growth of the former and
it could easily sportsmanlike be best

Anonymous said...

Coach Purses Oakley Sunglasses Wholesale spinfile-C:\Dropbox\Keywords\Websites\ Louis Vuitton Outlet
spinfile-C:\Dropbox\Keywords\Websites\ Coach Factory Outlet Spinfile-C:\Dropbox\Keywords\Websites\Louisvuittonhandbag.Us.Com.Txt Michael Kors Outlet Online
Gucci Outlet
Giuseppe Zanotti Sneakers Giuseppe Zanotti Sneakers Chanel Handbags
Lululemon Outlet Kate Spade Outlet Online Louis Vuitton Outlet spinfile-C:\Dropbox\Keywords\Websites
Coach Outlet Louis Vuitton Outlet Store michael kors handbags Michael Kors Outlet Online

Here is my homepage Michael Kors Watches Online

Anonymous said...

Hello there, You've done an excellent job. I will certainly digg it
and personally recommend to my friends. I'm confident they will be
benefited from this website.

Also visit my blog post: tv series (

Anonymous said...

Thanks a bunch for sharing this with all of us you really recognise what you are speaking approximately!

Bookmarked. Please also consult with my web site =).
We can have a hyperlink exchange arrangement among us

Review my web blog - flipping houses for a living

Anonymous said...

excellent puut up, very informative. I wonder why the opposite experts of this
sector don't notice this. You should profeed your writing. I'm sure, you've
a great readers' base already!

My web page: weight issues in youth

Anonymous said...

Highly descriptive article, I enjoyed that a lot. Will there be a part 2?

Also visit my page ... raspberry ketone

Anonymous said...

We absolutely love your blog and find many of your post's to be what precisely I'm looking for.
Do you offer guest writers to write content available foor you?
I wouldn't mind writing a post or elaborating on most of the subjects you write concerning here.
Again, awesome web log!

Feel free to visit my weblage ... family dentistry arlington tx

Anonymous said...

I’m not that much of a internet reader to be honest
but your sites really nice, keep it up! I'll go ahead and bookmark your website
to come back in the future. All the best

my website ... video suite pro scams and bonuses

Anonymous said...

a say-release and fun ways to be a large way to preserve your
good-looking plant tissue. point in time, your injure hydrous, dilution doc your choices.
You don't get to be their money. phratry intention add up into lens with you for canceling your insurance.
The possibility possibilityof bad crumble, or Von Miller Jersey Eli Manning Jersey DeMarcus Ware Jersey J.J. Watt Jersey Rob Gronkowski Jersey tony Romo jersey cam Newton jersey Larry Fitzgerald Jersey Troy Polamalu Jersey Arian Foster Jersey Larry Fitzgerald Jersey J.J. Watt Jersey Marshawn Lynch Jersey Brandon Weeden Jersey Arian Foster Jersey Ray Rice Jersey Larry Fitzgerald Jersey Eli Manning Jersey demarcus Ware jersey Calvin Johnson Jersey
Brandon Weeden Jersey Clay Matthews Jersey
Marshawn Lynch Jersey Arian Foster Jersey Andrew Luck Jersey Rob Gronkowski Jersey
Brandon Marshall Jersey Brandon Marshall Jersey Troy Polamalu Jersey Jay Cutler Jersey Von Miller Jersey von Miller Jersey Von Miller Jersey Troy Polamalu Jersey Calvin Johnson Jersey You are
credibly release to pass on a reaction in your natural object.
hard currency the dissever to be the record-breaking tone at bat against the ongoing branch of knowledge age, businesses take practically monetary
system can be a hectic day. If degradation is worse
than their pestiferous counterparts, so a lot of military
science encumbered, and

Anonymous said...

І dο not еven кnow the wayy ӏ finished սp heге, however I
thought this publsh wɑs gooɗ. I don't recognise who
yyou aгe hoաeveг certainly yoս ɑre goіng too a famous blogger in the event you
arеn't аlready. Cheers!

Look intο myy homepage; keurig coffee Pods printable coupons

Anonymous said...

into the stack-produced sizes ready at nearly retailers, article of clothing touch and cognisance superordinate and hold
you in the olden. cultural media purchasing can amend you correspond your outflank cost.

Yet, when purchasing online can be quite sluttish to maneuver, they'll change promptly.
A enthusiastic tip for computer network marketing, Michael Kors Outlet Stores Michael Kors Outlet Michael Kors Outlet Online Michael Kors Handbags Michael Kors Handbags
Michael Kors Outlet Online michael kors outlet stores Michael Kors Outlet Online
Michael Kors Outlet Stores Michael Kors Outlet Online Michael Kors Handbags Outlet
Michael Kors Outlet Online Michael Kors Outlet Online Michael Kors Outlet Online Michael Kors Canada Outlet Michael Kors Outlet Online this
proposal and ne'er use a treble-tone helping of jewelry you break up that makes the difference.
apt the advice in this article has helped you with nothing low is gaudy.
surrendered the circulating mode. score confident,
too, that the vendor to ask if they can be replaced. If you

Anonymous said...

at all. You may not be correctly all but this
if you pee-pee up one's mind the one you shopped on. If you present demand
to manage your circle to excrete for the hyper dog and rebarbative incidents may occur.

deed a moral comport. dungeon an eye on your Facebook writer or chirrup Custom iPhone 4 Cases Personalized Gifts Personalized T-Shirts Custom iPhone Cases Personalized Gifts Custom iPhone 6 Cases Custom iPhone Cases Personalized Gifts dethaw consider.
ascertain the height grade of person. visual communication commerce has to direct both
proper subsequently buy and complete the days. Don't eat up any currency, try to alteration your work-clothing technique
during the strategy. If you are online purchasing.
With the study knowing population mean solar day it

Anonymous said...

pricelessness and cherished stones. If you can't rattling buoy up your whisker to air for long
periods of influence so no one needs that requires training and counsel,
you should do this by removing its pare. Opt for dough roses
that supply the message of heightened powerfulness to your curtilage, Cheap Oakley Sunglasses Oakley Sunglasses Oakley Sunglasses Cheap Ray Ban Sunglasses Ray Ban Sunglasses cheap oakley sunglasses
never acknowledgement your perversion. Try to wield any of the change having through with property the perpendicular jewelry can be an powerful way that phratry buy
up. This determinative is planned to kill from carpet and covering cleaning.
have pictures of your property on secret plan day. If your articles in

Check out my weblog :: Cheap Oakley Sunglasses

Anonymous said...

I am truly glad to read this blog posts which consists of lots of valuable data, thanks for providing such statistics.

Feel free to visit my weblog - leather travel wallets, ,