Today I discovered that apparently the Microsoft.Web.Services2.Policy.PolicyExecutionStage type lives behind some sort of event horizon: no mention of it on the net (nor the use-net), if you exclude the usual msnd entry. Yet it's a very useful compass while you implement custom policy assertions, so I'm going to tell you what it is about. The following comes from observation of the WSE behaviour while handling a custom assertion.I'm not going in big details here, WSE documentation, quickstarts and good articles around supply excellent coverage of the syntactic sugar; however I need to contextualize the following, so I have to set up the stage: but promise me you'll go check serious sources later.A custom assertion is simply a class deriving from PolicyAssertion. Among other things, there are two methods you want to override:
An enforcer is simply a class implementing IPolicyEnforcer: an hymn to the saying "simple but effective", the interface exhibit a single member:
Now, a reasonable sequence with which the above are invoked looks pretty much like that:
Fairly simple model, very usable: great object model, good work. So far, however, it's not clear how a custom implementation may tell if a method is executing on the sending or the receiving sides: there are situations in which such a knowledge may come useful. Let's forget about the constructor, and let's consider all other methods:
OK, I'll get to the point. The stages through which policy processing goes through are formalized in a static variable of type PolicyExecutionStage, which you can find under the current policy context: PolicyContext.Current.Stage.PolicyExecutionStage is an enum of four values:
For eliminating the ambiguity of the IsSatisfiedBy execution environment I've added a trace inside every custom assertion method, displaying the state in which they were executing; and I applied my custom assertion to request and response on both the client and the web service.The result is that IsSatisfiedBy runs in the Compilation stage when on a sending side, while it is in Verification stage when it is running on a receiving end. Below my traditional OneNote snapshot.