2
votes

I'm developping a web service SOAP and I've defined my xsd schema and wsdl file, in which I want to validate the element comment (whose type is string) by fixing his max length. But when I validate the request with SoapUI, It seems to me the xsd schema doesn't validate the string max length.

This below is the syntax of my xsd schema :

<xsd:element name="comment" minOccurs="0">
    <xsd:simpleType>
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="20"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>

Anyone knows why? Thanks in advance.

1
Can you add more informations? .. Do you use some framework to publish your ws? .. etc .. add more detail in order to help you better. - Xstian
@Xstian I'm using cxf framework to publish my ws. I have schema validation enabled in my cxf-servlet.xml. - stevey

1 Answers

5
votes

SOAPUI validates the SOAP request against to its xsd correctly however you have to make a on purpose validation selecting the validate option right clicking on SOAP Request window (as its showed in the last picture), if you send the request directly without validate it, SOAPUI simply sends the request even if it's a bad formed xml because SOAPUI is a testing tool an you maybe want to send a bad request on purpose to test your WS.

I make a sample with maxLength <restriction> in <xs:string> an I get the follow result (I'm using SOAPUI 4.5.2):

enter image description here

To do this I use the follow wsdl:

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:impl="sample:wsdl"
    xmlns:dss="sample:schema"
    targetNamespace="sample:wsdl" name="dss">
    <!-- Schema Type Definitions -->
    <types>
        <xs:schema xmlns:dss="sample:schema" 
        xmlns:xs="http://www.w3.org/2001/XMLSchema" 
        targetNamespace="sample:schema" elementFormDefault="qualified" 
        attributeFormDefault="unqualified">
            <!-- COMMON PROTOCOL STRUCTURES -->
            <xs:element name="comment" minOccurs="0">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:maxLength value="20"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
        </xs:schema>        
    </types>
    <!--Messages-->
    <message name="CommentRequest">
        <part name="CommentRequest" element="dss:comment"/>
    </message>
    <!-- PortTypes -->
    <portType name="SOAPport">
        <operation name="doComment">
            <input message="impl:CommentRequest"/>
            <output message="xs:anyType"/>
        </operation>    
    </portType> 
    <!-- Bindings -->
    <binding name="SOAPBinding" type="impl:SOAPport">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="doComment">
            <soap:operation/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>
    <!--Service definition-->
    <service name="doCommentService">
        <port name="dssPortSoap" binding="impl:SOAPBinding">
            <soap:address location="http://testing.stackoverflow.answer"/>
        </port>
    </service>
</definitions>

As you can see in the wsdl the CommentRequest as the follow schema with maxLength <restriction>:

<xs:schema xmlns:dss="sample:schema" 
            xmlns:xs="http://www.w3.org/2001/XMLSchema" 
            targetNamespace="sample:schema" elementFormDefault="qualified" 
            attributeFormDefault="unqualified">
    <!-- COMMON PROTOCOL STRUCTURES -->
    <xs:element name="comment" minOccurs="0">
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:maxLength value="20"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
</xs:schema>

Then I create a new SOAPUI project from the wsdl and add a SOAP Request, if I put a string with more than 20 characters in <comment/> and press right click on SOAP Request window and select Validate it give you the error message showed in the first picture:

enter image description here

Hope this helps,