title: How do I get an Axis/Castor web service to validate the request against the XSD?
body: <p>I've developed a small web service in a contract-first (top-down) fashion using an XSD developed by another team within our organisation. The problem I'm having is that if the request is slightly malformed the service still runs. I really need it to validate the request against the XSD, but I don't know how to force Axis or Castor to do that.</p>
  
  <p>When I say "slightly malformed" I mean that the request contains the right elements, but not quite sequenced correctly. A truly malformed request will be rejected during Castor unmarshalling. A slightly malformed request will unmarshall, with potentially unwanted results. Here's an example:</p>
  
  <p>A valid request should contain a list of items presented like this:</p>
  
  <pre><code>&lt;ItemList&gt;
    &lt;Item&gt;Value1&lt;/item&gt;   
    &lt;Item&gt;Value2&lt;/item&gt;   
    &lt;Item&gt;Value3&lt;/item&gt;   
  &lt;/ItemList&gt;
  </code></pre>
  
  <p>This will unmarshall correctly and the web service will process all three values.</p>
  
  <p>However, I've discovered that if the same set of values is presented like this:</p>
  
  <pre><code>&lt;ItemList&gt;
    &lt;Item&gt;Value1&lt;/item&gt;   
    &lt;Item&gt;Value2&lt;/item&gt;   
  &lt;/ItemList&gt;
  &lt;ItemList&gt;
    &lt;Item&gt;Value3&lt;/item&gt;   
  &lt;/ItemList&gt;
  </code></pre>
  
  <p>Then this will also unmarshall in the same manner as the first example, and all three values will be processed. In this case the end result is acceptable, but this structure is incorrect according to the XSD and I'd prefer it to create a fault. </p>
  
  <p>Here's the request definition taken from the XSD: </p>
  
  <pre><code>&lt;xsd:complexType name="SampleRequestType"&gt;
    &lt;xsd:sequence&gt;
      &lt;xsd:element name="ItemList" minOccurs="1" maxOccurs="1"&gt;
        &lt;xsd:complexType&gt;
          &lt;xsd:sequence&gt;
            &lt;xsd:element name="Item" type="xsd:string" minOccurs="1" maxOccurs="unbounded"/&gt;
          &lt;/xsd:sequence&gt;
        &lt;/xsd:complexType&gt;
      &lt;/xsd:element&gt;
    &lt;/xsd:sequence&gt;   
  &lt;/xsd:complexType&gt;
  </code></pre>
  
  <p>SoapUI reports the second example as invalid, so I'm convinced that the XSD is correct.</p>
  
  <p>I've tried a few things to force XSD validation to take place, to no effect so far. Does anyone know how to force Axis or Castor to validate?</p>
  
  <p>For historic reasons I'm using old versions of these two components - Axis 1.3 and Castor 1.1 but I'm willing to suffer any upgrade pain if I can get the XSD validation working.</p>
  
  <p>Many thanks</p>
  
  <p>Steve</p>