Validation of request body against a XSD

Not applicable

I know this has probably been discussed numerous time but I have been unable to find a resolution to my issue. I am trying to do schema validation of a request against a defined XSD. None of our XSD's have namespaces associated with them and they all have library schema's that get get called in using the <xs:include schemaLocation= statement. I know this may be a simple fix, but I have yet to find it. Any help would be appreciated.

My XSD is formatted as below:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:include schemaLocation="TrackingInfo.xsd"/> <xs:include schemaLocation="NewResponseHeaderInfo.xsd"/> <xs:include schemaLocation="NewUserInfo.xsd"/> <xs:element name="EPS"> <xs:annotation> <xs:documentation>Gets Subscriber information for the given MDN</xs:documentation> </xs:annotation> <xs:complexType> <xs:sequence> <xs:element ref="ServiceHeader"/> <xs:element ref="TrackingInfo" minOccurs="0"/> <xs:element name="Request" type="Request"/> <xs:element name="Response" type="Response" minOccurs="0"/> </xs:sequence> </xs:complexType>.....</xs:schema>

This is my MessageValidation policy:

<MessageValidation async="false" continueOnError="false" enabled="true" name="SubscriberInquiry-Validation"> <DisplayName>SubscriberInquiry-Validation</DisplayName> <FaultRules/> <Properties/> <Element namespace="http://www.w3.org/2001/XMLSchema">EPS</Element> <Source>request</Source> <ResourceURL>xsd://SubscriberInquiry.xsd</ResourceURL> <ResourceURL>xsd://TrackingInfo.xsd</ResourceURL> <ResourceURL>xsd://NewResponseHeaderInfo.xsd</ResourceURL> <ResourceURL>xsd://NewUserInfo.xsd</ResourceURL> </MessageValidation>

The validation is being invoked but I receive the below error message:

{"fault":{"faultstring":"SubscriberInquiry-Validation failed with reason: \"Unexpected Root Element EPS [Line 1]\"","detail":{"errorcode":"steps.messagevalidation.Failed"}}}

If I add a namespace to the XSD, I get the same error response.

If I remove the namesapce entry from the MessageValidation policy, I get the below error:

{"fault":{"faultstring":"SubscriberInquiry-Validation failed with reason: \"Element name mismatch. Wildcard? [Line 1]\"","detail":{"errorcode":"steps.messagevalidation.Failed"}}}

This is my request XML:

<EPS> <ServiceHeader> <ServiceName>SUBSCRIBERINQUIRY</ServiceName> <Operation>GetSubscriberInfo</Operation> <ClientId>UDIVR</ClientId> <UserInfo> <UserId>ramadha</UserId> <UserClass/> </UserInfo> </ServiceHeader> <Request> <MDN>8063957999</MDN> </Request> </EPS>

Solved Solved
1 6 1,480
1 ACCEPTED SOLUTION

Rick, thanks for the information. I've been away for a few days. Is the still a problem? Have you got it working?

If you like I can look into it, but you need to send all the dependent XSDs. NewUserInfo.xsd, NewResponseHeaderInfo.xsd and TrackingInfo.xsd .

I think the correct policy configuration for your scenario is like this:

<MessageValidation name="MessageValidation-1">
  <Source>message</Source> <!-- must be message type -->
  <ResourceURL>xsd://SubscriberInquiry.xsd</ResourceURL>
</MessageValidation>

Note: no reference to any additional dependent XSDs in that configuration.

And your root XSD must reference the included XSDs like this:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:include schemaLocation="xsd://TrackingInfo.xsd"/>
	<xs:include schemaLocation="xsd://NewResponseHeaderInfo.xsd"/>
	<xs:include schemaLocation="xsd://NewUserInfo.xsd"/>
	<xs:element name="EPS"> ...

Note the xsd:// prefix in the value of each schemaLocation.

Finally, the dependent XSDs must be included in the proxy under /resources , along with the main XSD.

I'm sorry, I think the documentation for this policy, in this scenario, is lacking in clarity and completeness.

View solution in original post

6 REPLIES 6

Not applicable

Zip file contains the XSD, request XML and validation policy>

subscriberinquiry-validation.zip

Rick, thanks for the information. I've been away for a few days. Is the still a problem? Have you got it working?

If you like I can look into it, but you need to send all the dependent XSDs. NewUserInfo.xsd, NewResponseHeaderInfo.xsd and TrackingInfo.xsd .

I think the correct policy configuration for your scenario is like this:

<MessageValidation name="MessageValidation-1">
  <Source>message</Source> <!-- must be message type -->
  <ResourceURL>xsd://SubscriberInquiry.xsd</ResourceURL>
</MessageValidation>

Note: no reference to any additional dependent XSDs in that configuration.

And your root XSD must reference the included XSDs like this:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:include schemaLocation="xsd://TrackingInfo.xsd"/>
	<xs:include schemaLocation="xsd://NewResponseHeaderInfo.xsd"/>
	<xs:include schemaLocation="xsd://NewUserInfo.xsd"/>
	<xs:element name="EPS"> ...

Note the xsd:// prefix in the value of each schemaLocation.

Finally, the dependent XSDs must be included in the proxy under /resources , along with the main XSD.

I'm sorry, I think the documentation for this policy, in this scenario, is lacking in clarity and completeness.

@Dino
I was able to get this working once I stumbled across the correct format to include the sub-schemas. I agree with you that the policy is not very well documented but I got working.

Thanks Dino

@Floyd Jones - what do you think, could we update the doc for MessageValidation to include a couple examples? one for SOAP and one for "validate against this XSD" (as shown here)?

Thanks, @DinoChiesa-at-Google. I've filed a ticket for this (79144844).

FYI, I updated the SOAP Message Validation policy documentation to include examples of validating an XSD and WSDL, as well as examples of checking JSON and XML for well-formedness. I also expanded some of the child elements' doc on that page.

Hth,

matt