Friday, April 27, 2012

Declaratively ignoring must understand headers


A soap header may specify a "must understand" flag. This instructs any processing node to throw an exception if this header is not understood by it. Such a behavior is sometimes useful and sometimes very annoying, depending on the circumstances. Let's see how such header looks like in soap:

By default a Wcf service will validate all incoming mustUnderstand headers a client sends. If it does not understand them it will throw the famous 'Did not understand "MustUnderstand" header' exception. Typically you would instruct Wcf not to validate these headers like this:

But this kind of "hard codes" this behavior to the service. Wouldn't it be nice to decide at the configuration level if we want such a behavior or not?

All we need to do is define this class:

Then in the config register it:

And we can now configure our endpoint(s) with this behavior:


What's next? get this blog rss updates or register for mail updates!


Uas Ku Sukses said...

Hi Yaron,

Kindly need help you advise about my problem.

I've tried to add MustunderstandBehaviour to my service

MustUnderstandBehavior mustUnderstand = new MustUnderstandBehavior(false);
mustUnderstand.ValidateMustUnderstand = false;


but it seems the mustundertand = "1", i want to change from "1" to "0"


Yaron Naveh (MVP) said...

to set mustunderstand to 0 you should implement a custom encoder. I believe you want to set it for outgoing requests while this post deals with incoming responses.

Uas Ku Sukses said...

Hi Yaron,

Yes, I've tried to make a custom encoder to make it became 0, but after im save the modified xml. I got the canonical issue. It seems the format should be followed canonical format.

Need your advise!!

Yaron Naveh (MVP) said...

not sure I understand, what is the canonical issue?