Friday, July 9, 2010

Interoperability Gotcha: Soap Headers


A soap message may contain any number of user defined headers:

<Envelope xmlns="">





The list of possible headers may be defined in the wsdl:

   <xs:element name="MyHeader" type="xs:string"/>
<part name=”h” element=”tns:MyHeader” />

we can see that:

1. MyHeader is a root level element in the schema so it cannot be optional (minOccurs=0).
2. The wsdl schema prohibits a minOccurs attribute on the "part" element.

So it seams every soap header is mandatory and cannot be omitted from the soap. Such a behavior is also the recommendation of the WSI basic profile.

Nevertheless, some frameworks (for example .Net 2.0 and WCF) do not force clients do send the headers nor do they enforce the existence of such on the server side. This results in the following interoperability guidelines:

  • When building a server, do not assume that all clients will always send all headers (e.g. check for null values)

  • Do not assume that all clients can omit headers (e.g. some client stacks require it). For this reason do not develop any logic which depends in the existence or absence of headers.


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