I wrote a slightly Twitter-inspired, fun app over the weekend that's using the BizTalk Services Connectivity service and relay. In the spirit of Software+Services I'm going to give you half of it [for now] ;-) You must have the BizTalk Services SDK installed to run the sample. The server app, which I'm keeping to myself for the next few days as part of the experiment, is an extension (add-in) to Windows Live Messenger. The Messenger add-in monitors all chats with tweetiebot@hotmail.com and keeps circular buffer with the last 40 incoming messages. Using the client (which is in the attached archive), you can get a list of "Tweets" and add a new one (same as chatting) [ ServiceContract (Name = "TweetieBot" , Namespace = http://samples.vasters.com/2007/05/tweetiebot )] public interface ITweetieBot { [ OperationContract ] IList < Tweet > GetTweets( DateTime ? since); [ OperationContract ] void Tweet( string nickname, string text); } or you can subscribe to new tweets and get them as they arrive [ ServiceContract (Name = "TweetieEvents" , Namespace = http://samples.vasters.com/2007/05/tweetiebot )] public interface ITweetieEvents { [ OperationContract (IsOneWay= true )] void OnTweet( Tweet tweet); } The client application hooks up to the client (that lives right on my desktop machine) through the BizTalk Services ISB and the server fires events back through the ISB relay into the client as new tweets arrive. So when you run the attached client app, you'll find that it starts with a dump of the current log of the bot and then keeps spitting out events as they arrive. The client is actually pretty simple. The EventsClient is the subscriber for the pub/sub service (ConnectionMode.RelayMulticast) that writes out the received events to the console. The rest all happens in Main (parsing an validating the command line argument) and in Run . class Program { class EventsClient : ITweetieEvents { public void OnTweet( Tweet tweet) { Console .WriteLine( "[{0}] {1}:{2}" , tweet.Time, tweet.User, tweet.Text); } } static void Main( string [] args) { string usageMessage = "Usage: IMBotClient <messenger-email-address>" ; if (args.Length == 0) { Console .WriteLine(usageMessage); } else { if (! Regex .IsMatch(args[0], @"^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$" )) { Console .WriteLine(usageMessage); Console .WriteLine( "'{0}' is not a valid email address" ); } else { Run(args[0]); } } } private static void Run( string emailAddress) { EndpointAddress serviceAddress = new EndpointAddress ( String .Format( String .Format( "sb://{0}/services/tweetiebot/{1}/service" , RelayBinding .DefaultRelayHostName, Uri .EscapeDataString(emailAddress)))); EndpointAddress eventsAddress = new EndpointAddress ( String .Format( String .Format( "sb://{0}/services/tweetiebot/{1}/events" , RelayBinding .DefaultRelayHostName, Uri .EscapeDataString(emailAddress)))); The URI scheme for services that hook into the ISB is "sb:" and the default address
Read More...