I’ve created a web service using WCF.
I cannot figure out how to set the constraints and the restrictions in the WSDL/XSD through the data contract.
What if I improve the XSD2 schema with the constraints and then bind this custom schema to the existing service? If so, how can I make the service expose the improved WSDL?
Otherwise, is there any other way to set the metadata for a WCF service?
This seems to be a common problem. The service metadata describes the data contract. That is, the structure of the exchanged data, without any validation information.
I have been solving this problem by implementing a validation layer on top of the service layer. It goes as follow:
In addition to a WSDL, the service author and consumer also agree on a refined XSD that describes all the validation details in addition to the mere structure of the data contracts.
Each party (xml) serializes and validates the data contracts against the refined XSD.
Sample “pseudocode” for a service method that validates the request agains an XSD.
The service consumer can also implement a similar logic to validate the request data before sending it to the server.