One Solution For Handling Base Addresses in the Jan CTP of WCF

by Matt Milner 21. February 2006 06:11
One of the changes that occurred on the way to the Jan CTP of WCF was that you must supply a base address to the service host class when constructing it in order to get a metadata access point.  You now use the base address to access the meta data documentation page and can't just use an absolute address in the configuration file and get metadata.  Note that you can still use an absolute address in the configuration file, you just don't automatically get a documentation/metadata functionality if you don't use the base address as well. 
The problem with this is that all of the examples from Microsoft using this new requirement show reading these base addresses from the appSettings in configuration files. This is for good reason.  If anything is going to change in your addressing as you move from one environment to the next, it is probably the base address where you include server names, so it makes sense to store this information in the configuration file so that it can be easily updated without having to recompile the service code.  Being a lazy programmer, I don't want to have to write the same configuration code over and over, so I created a service host base class that does it for me. 
My example, which can be found here, defines the service host derived class that you can use to host your services along with the appropriate configuration code to allow for a custom configuration section that contains the base addresses for your service. The service host base class overrides the OnApplyConfiguration method and adds the addresses from the configuration file into the collection of base addresses for you. 
Feel free to try it out and provide any feedback.  I don't know what the final plans are from MS on this, but hopefully this will make someone's life a bit easier, at least in the short term. 
 
Update: some people have had trouble opening this solution.  The solution was created in VS 2005 Team Edition for Software Developers. It contains the main project as well as a test project and some solution items.  If you experience trouble, simply open Visual Studio 2005 and open the single project (PS.WCF.Configuration) which is a simple c# project. 
 
Update: I've updated this sample to work with the Feb CTP.  I don't like this solution as much b/c it is not as clean, but the BaseAddresses collection is now readonly so I can't update it in the ApplyConfiguration method.  Instead, I am creating the collection in my constructor, which I really don't like, but it does work.  I'm hoping this gets easier in the later releases, not harder.

Tags:

Windows Communication Foundation

"Beta 2" of WinFX (WCF, WPF and Workflow Foundation) has arrived

by Matt Milner 18. January 2006 09:47
The Jan CTP for these products is now up on the Microsoft website and they even have go live licenses available!  I know a lot of people are eager to get a look at the updates, especially with workflow, so let the downloading begin!  http://msdn.microsoft.com/winfx/getthebeta/golive/default.aspx

Tags:

Windows Workflow Foundation

MSDN Magazine article on VS.Net Templates

by Matt Milner 4. January 2006 15:26
My article on VS.Net templates is finally up on the MSDN Magazine web site [1].  I had a lot of fun diving into this feature and look forward to being able to use them in creating classroom materials and templates for my customers. 
 

Tags:

General Musings

Back to blogging

by Matt Milner 4. January 2006 15:23
Well, I apologize for being so lax in my posting.  I finished off the year with a bang and haven't had time to post.  I've been traveling to exotic places like Bangalore, India. I had a great time with some ISVs and the folks from Microsoft talking about Workflow and Windows Communication.  This was my first trip to India and it was a fun one.  I did have some huge trouble with jet lag; I didn't sleep until the fourth night there and it took me a full week to get a decent night sleep.  But, all that aside, I had a great time with some fabulous food, great hospitality, and lots of good conversation about technology! 
 
Starting off the new year, I am going to try and get some posts out before I head out to London and Paris in a couple of weeks.  I've got a post that I'll put up tonight along with this one related to the business rules engine in BizTalk.  I'll also be posting some items on workflow and some sample activities that will hopefully prove helpful in showing off features. 
 
 

Tags:

General Musings

Understanding the FactHandle in a FactRetriever

by Matt Milner 4. January 2006 15:23
One of the most confusing things, other than that pesky document type problem, that developers I work with run into with the business rules engine in BizTalk is understanding the role of the fact handle when implementing a fact retriever. 
 
A FactHandler, for those that are not familiar, is a class that one implements in order to supply long term facts to the Business Rule Engine in BizTalk Server.  Common items returned include database connections or tables, or xml content from a database or file.  The business rule engine calls the fact handler on each invocation of any policy it is configured on to get these facts.  It is the job of the fact retriever to make sure that it provides up to date information as appropriate and caches data or variables where necessary. 
 
It would seem, from the name of the variable, "factHandle", and the way it is passed to the single function in the IFactRetriever interface, that this object is actually the fact(s) being returned by the fact handler.  In reality, however, this object is actually the item that helps the fact retriever be smart about caching and retrieving data.  The act of getting facts into the rule engine occurs by Asserting items into the engine within the fact retriever method. 
 
The fact handle is the object that your fact retriever creates the first time it is called.  This object is then passed back in to your fact retriever each time the retriever is called so that it can use this information to determine if it needs to refetch data or just allow the business rule engine to use the data it returned last time.  A simple, yet effective example, is to return a DateTime struct on the first request and then, on subsequent calls, check it against a configured timeout to determine if you should fetch data again. 
 
The code below shows both the UpdateFacts method as well as a helper method to determine if the facts are out of date. 
 
public object UpdateFacts(RuleSetInfo ruleSetInfo, RuleEngine engine, object factsHandleIn)
{
  object factsHandleOut = null;
  if(factsHandleIn == null || FactsAreOutOfDate(factsHandleIn))
  {
    //Assert facts into the engine at this point using the "engine" parameter
 
    //If this is the first time here, or we are out of date
    //then update the facts handle to the current time
    factsHandleOut = DateTime.Now;
  }
else
{
  factsHandleOut = factsHandleIn;
}
  return factsHandleOut;
}
 
 
private bool FactsAreOutOfDate(object factsHandle)
{
  DateTime lastUpdateTime;
  if(factsHandle == null)
     return true;
  if(factsHandle is DateTime)
  {
    lastUpdateTime = (DateTime)factsHandle;
    return (TimeSpan.Compare(DateTime.Now.Subtract(lastUpdateTime),
                    TimeSpan.FromDays(1)) > 0);
  }
  else
    return true;
}
 
In the first method, we test for the fact handle to be null or to be out of date.  We do a simple check to see if the facts are more than a day old.  If they are, then we return true so that we know to reassert the facts. Back in the UpdateFacts method, we either return the original facts handle if we don't want to make any changes, or we return the current time if we are asserting new facts and want to reset our "timer". 
 
This is obviously a simple example and might be extended by using a class or struct to wrap multiple DateTime structs representing different facts. That is, we might not want to treat all of the facts with the same policy, so we can have timeouts for different facts.  A database connection we might not refresh, but a datatable we might refresh every few hours. 
 
Hopefully, this information will be helpful to people trying to work with the business rules engine in BizTalk. 
 

Tags:

BizTalk Server

The difference a checkbox can make

by Matt Milner 3. October 2005 21:13

I was doing some work recently on upgrading BizTalk 2004 projects to 2006 and had been using the same web services that I had originally published using the BTS 2004 wizard.  I had some changes to make and so I fired up the BTS 2006 web services publishing wizard, not expecting to find much new.  However, one checkbox made the experience worth it.  It said: Merge selected ports into a single web service.  Glorious!  I can't tell you how many times I have had to either create a single port definition, shared by multiple orchestrations, so that I could publish one instance of the port, or hand editing the published web services to get a single service. 

In addition to this one simple change, there is another change that I was glad to see with this wizard.  You can now use the SoapParameterStyle.Bare option to have a little more control over the WSDL contract for your service.  This is especially useful if you are trying to implement an existing interface that requires this style of parameter passing.  You access this with the advanced button on the additional settings page when you are setting things like web service namespace and SOAP header support. 

Additions like these will continue to make BizTalk the tool of choice for implementing SOA.

Enjoy the update wizard, I know if will. 

Tags:

Week of Workflow Webcasts

by Matt Milner 15. September 2005 03:05

If you are interested in finding out more about Windows Workflow Foundation (WWF) then you should check out the upcoming week of webcasts.  See Paul's Blog for more details. 

Tags:

Windows Workflow Foundation

Windows Workflow Foundation- What about BizTalk?

by Matt Milner 14. September 2005 12:42

So, with the big announcement about the upcoming release of Windows Workflow Foundation (WWF - gotta love that acronym; I was surprised not to see Hulk Hogan here presenting), many BizTalk developers have already started asking what this means for BizTalk Server. 

The simple answer is that BizTalk 2008 (or whatever the official name becomes, but not 2006) will host the workflow runtime for its orchestration capabilities and will extend workflow with all of the great things you've come to expect from BizTalk.  BizTalk Server will be your enterprise solution for scalable, reliable message based integration, business process management and SOA applications and services.  BizTalk will be providing MANY important features on top of the basic workflow foundation that you will want for your EAI, B2B, and SOA apps, like pipelines, adapters, management, infrastructure, security, etc.  So, before you run off and say, "With WCF ("Indigo") and WWF, I can build my own BizTalk"; think twice, or maybe five times.  The BizTalk team has years of experience and customer data points for building the manageability, scalability and reliability that an application of this type demands and they will continue to deliver a product that goes far beyond the capabilities of the WWF. 

However, the great news is, skill sets in WWF, which will likely reach more developers, will be greatly applicable to BizTalk Server 2008 development.  And, because the workflow foundation is extensible, it is likely that BizTalk developers will get their biggest wishes answered in two ways.  1) BizTalk Server 2008 will almost definitely include VS.Net debugging for orchestrations as this is already built into WWF. 2) BizTalk 2008 will easily have the ability to allow developers to create and use custom actions, and we'll have to watch for the product team to include. 

All that being said, and my passion for BizTalk being obvious, WWF is hugely powerful framework on its own and will allow developers to create amazing applications while improving their productivity.  The activity model will also help in the ever present goal of making reusable components.  So, I'm very excited about WWF, and glad we can now talk about it publicly.  Look for more information here on my blog and the Pluralsight web site for upcoming announcements related to WWF, WCF and BizTalk. 

 

Tags:

BizTalk Server | Windows Workflow Foundation

China, Iowa, and in between

by Matt Milner 1. September 2005 06:05

So my lame excuse for not blogging for months is that I have been traveling all over the world.  That's not entirely true, and I've certainly had time in the office, I've just been finding a lot to do.  So, here is the run down of what I have been doing, and more importantly, what I plan on doing and blogging about in the next couple of weeks.

So first off, I went to Shanghai, China to deliver the Applied Web Services class for a group of Microsoft folks there.  It was a great bunch of people with varying reasons for being interested in web services.  The trip was fabulous and it was a great experience for me, having never been to China.  Sorry, I don't have any pictures yet, as that is another thing I haven't gotten around to: taking my disposable camera in for development. 

So that was my excuse for June, that and Tech Ed, but then I had to get ready for RAGBRAI, the great bicycle ride across Iowa. My in-laws have been doing the ride for years, and having grown up in Iowa, I had always wanted to try it so this was the year.  485 miles was tough on some days, but I made it through and even made it up the big hills without having to get off and walk.  If I do it again next year, I'll be sure to train a little harder for those hills.  We had a lot of fun and took my 1 year old son along.  The first night we camped with him in a tent and had 70 MPH winds and downpour of rain.  He slept through some of the loudest thunder claps, and only woke up and got upset in the morning when he realized he was soaking wet.  He's a trooper!  

So what's coming up: 

PDC - I'll be there, just doing the attendee thing this time and excited to learn about Office 12 and workflow.  I'll probably check out an Indigo talk or two as well.  :) 

HDC - The heartland developer conference is Oct 12 - 14 and will be a lot of fun.  If you are in the central region you should check it out.  I'm presenting on XML in SQL Server and I'll be looking at the server side as well as programming the client side. 

I've got an article coming out in MSDN magazine on Visual Studio Templates and Starter Kits.  When I have a definite date, I'll pass it along.  For us trainer types, these are very cool as they allow us to reuse initial solutions over and over.  The article, however, is geared toward business/enterprise developers who want to leverage templates for projects and items to have some consistency in their organization.  These are very cool stuff and hopefully the article will help you get started with them. 

Now, for blogging, I have lots to write about, including BizTalk pipeline configuration and dynamic message part creation in orchestrations and pipelines.  I've also done some fiddling with BizTalk web services for a project I'm working on and hope to share some insights on how to tweak those generated services when you need/want to.  In addition, I'll be posting on some of the new features in BizTalk 2006 that I really like around web services, pipelines and orchestrations.  

 

Tags:

ASP.Net SQL Cache Dependencies with SQL 2005

by Matt Milner 15. June 2005 04:33
I was testing out some ASP.Net features and got SQL cache dependencies working just fine with SQL 2000.  However, I wanted to  see the new features of SQL 2005 using query notification to get immediate cache invalidation without polling the database.  I couldn't find any documentation, so I did a little spelunking.  It turns out that instead of configuring a dependency and referencing it in the properties for the SQL data source like you do for SQL 7.0 and 2000, you use "CommandNotification" as the SQL cache dependency property.  This tells ASP.Net that you are using SQL 2005 and it then correctly uses query notification instead of trying to use the polling mechanism that is required for earlier versions of SQL. 
 
The great thing about this solution is that it does not require you to run any setup scripts or create triggers and stored procedures in your database.  It does however require that you enable Service Broker on your SQL database which is not enabled by default for security reasons. 
 
I hope this helps some other people trying out the betas. 

Tags:

SQL Server 2005