How to define the XPath expression

This post is part of Issue 5’s answer

As a result of step 1 (How to define a <MessagePredicate>) we go the following template for our <MessagePredicate>

   <wsp:MessagePredicate wsp:Usage="wsp:Required">

  wsp:GetBody(.)/ here/goes/my/path > 4


Given our CLR message type:


public class Issue5ReqMsg


   public int something;


It’s tempting to define the following XPath expression:

<wsp:MessagePredicate wsp:Usage="wsp:Required">

  wsp:GetBody(.)/Issue5ReqMsg/something > 4


Ok, we’ve forgotten to define the element’s namespaces. By doing so, the expression looks the following:

<wsp:MessagePredicate wsp:Usage="wsp:Required" xmlns:it=”uri:isssue5/types“ >

  wsp:GetBody(.)/it:Issue5ReqMsg/it:something > 4


But does this really work?

Let’s have a look at the message that will be sent across the wire:

<soap:Envelope xmlns:xsi=""




            < reqMsgxmlns ="uri:isssue5/wsdl">

  <something xmlns="uri:isssue5/types">6</something>




Ooops, surprise, surprise, there is no element called <Issue5ReqMsg> instead there is an element called <reqMsg>, but why?

A quick look at the wsdl file answers the question:

<types xmlns:s=""





   <s:schema elementFormDefault="qualified" targetNamespace="uri:isssue5/wsdl">

  <s:import namespace="uri:isssue5/types" />




   <s:schema elementFormDefault="qualified" targetNamespace="uri:isssue5/types">

  <s:complexType name="Issue5ReqMsg">


  <s:element minOccurs="1" maxOccurs="1" name="something" type="s:int" />



  <s:complexType name="Issue5RespMsg">


  <s:element minOccurs="1" maxOccurs="1" name="something" type="s:int" />





  <message name="DoSomethingSoapIn">



      <message name="DoSomethingSoapOut">



Our document literal Web Service requires an element within its message part. Therefore, the two elements reqMsg and DoSomethingResult have been created. Note that these two elements contain to another namespace than the two corresponding types. The next post will discuss how the creation of these elements can be controlled using .NET attributes.

Coming back to our quiz, the XPath expression has to look the following:

<wsp:MessagePredicate wsp:Usage="wsp:Required"

xmlns : it ="uri:isssue5/types"

xmlns : iw ="uri:isssue5/wsdl">

      wsp:GetBody(.)/iw:reqMsg/it:something > 4