Wow! It's been a long time since I've blogged about anything! It seems every time I think of something to blog about, I find some other blog that already talks about the same thing. I guess it's best I get over this because you never know who will find who's blog.
After being in the trenches for so long with WF 3.0/3.5, SharePoint WF and WCF, I have finally had the opportunity to start digging into WF 4 & Visual Studio 2010 Beta 1. Workflow is headed for a very bright and exciting future, but like all new things, it's going to take some getting used to.
So today, let's start by creating a 'Declarative Sequential Service Library' (workflow exposed as a WCF service). But first, lets understand a few things about this type of service.
What will this example service represent?
Since spend a week every year at summer camp, I've decided to create a simple service that will confirm space in merit badge classes for summer camp. In our case to keep this simple, we will simply confirm space for any merit badge request. We will not be doing any sort of correlation in this example, we'll save that for later blog entries.
Creating the Service
As it stands at this point, you'll notice that you have an Operation Name of GetData, a Value of 'data' and no Correlates with value. You may recall from Visual Studio (2008/2010) that if you were to have selected just to create a WCF service, it would provide for you a contract named IService with an operation named GetData. This is the same sort of thing that is happening here. We are going to change these values though.
Here is the data type we will be referencing within our service (I created this by creating a class library named MeritBadgeType and putting it in the same Visual Studio solution):
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using System.Runtime.Serialization; namespace MeritBadgeType { [DataContract] public class MeritBadge { private string _mBadgeName = default(string); private Int16 _mBadgeSession = default(Int16); [DataMember] public string BadgeName { get { return _mBadgeName; } set { _mBadgeName = value; } } [DataMember] public Int16 BadgeSession { get { return _mBadgeSession; } set { _mBadgeSession = value; } } } }
Setting up the Activities
Now comes the tricky part. If I were to go and try to add a service reference to this service in a client app, what it would show me is that my actually service name is IService1, not IConfirmService. So how do we get this to work?
In the end, your declarative service should look something like this:
Setting up the Service Name
Notice that in the config file, we need to change the name of the service being referenced to 'MeritBadgeService' which is the same name as the .xamlx file. Another thing you might notice is that you don't see an endpoint configured with an address or binding type. This is because, out of the box, this declarative service assumes you will be using basicHttpBinding and the address will be http://localhost:<someport>/MeritBadgeService.xamlx. Also notice that metadata exposure is enabled.
What we just did here (remember this is Beta 1 bits) is, to change the exposed service name, we had to go into the source code and change the service name. To re-open the MeritBadgeService.xamlx file in the workflow designer, double-click on it in the solution explorer. Rebuild the entire solution.
Testing the Service
…and if you click on the wsdl link, you'll be able to see that indeed the service name is 'MeritBadgeService':
What about a real test?
For a real test, you can pretty much choose any type of client where you can add a service reference to (and that can call a basicHttp endpoint). What you need to do is add a service reference to the address: http://localhost:1068/MeritBadgeService.xamlx from the above example and the service reference will be added to your project. More info in the next post about how to set this up.
Thank you for submitting this cool story - Trackback from DotNetShoutout
It's been three months! Are you still planning on posting on "how to set this up"?
I've got a declarative sequential service working with a custom type, set up as a DataContract as in this post, and can use it from the WcfTestClient but I'm having a devil of a job to get a Sequential Workflow Console Application to be able to talk to it.
Simon,
When I last wrote this, this was beta 1. Many things have changed now which will result in me have to just start again on it to see what has changed. I currently (within the next week or two) don't plan to do this but will eventually. I wanted to wait until they get closer to beta2 so I didn't have to once again go through it.
Sorry.