3

I have a wcf service in 1 project and an object model that holds all my objects in another project. I add a reference to the object model in the service project and am able to use the objects in my service without incedent.

When I publish the service and other users use it. They are able to enter invalid data and schema and the service does Not fail.

I need the service to be connected to the object model. If users to not adhere to the schema of the objects the service should fail automatically.

Im am not sure if maybe I have to set a configuration maybe in the web.config?

What I am not understanding is if I set a property on an object to required. If the user does not add this property to the object being passed to the service why isnt the service automatically stopping?

[DataMember(IsRequired = true)]
        public string VendorName { get; set; }
Nick LaMarca
  • 8,076
  • 31
  • 93
  • 152
  • If the clients of your WCF service are generating their code from the WSDL published by the service, you will always get valid soap messages (schemas) to your service. WCF performs the translation of soap XML messages between the clients and the service, but it is the service logic that must handle processing the *contents* (data) of the messages. – Sixto Saez Apr 25 '12 at 14:38

1 Answers1

2

WCF automated approaches

To automate the WCF validation against its WSDL contract, you could use the WsdlExporter as shared in this MSDN blog.

WCF raw approaches

  1. You could use a WCF schema validation behavior extension. The custom BehaviorExtension will allow you to enforce data validation of a defined schema.

  2. You could also use a WCF parameter validation behavior extension to enforce parameter constraints.

    See MSDN for WCF Input/Data Validation FAQ.

WCF Validation Commentary

Also review this great SO post regarding why WCF input/data validation isn't performed.

The Four Tenets of XML Messaging with WCF also provides an interesting perspective on Schema validation.

Community
  • 1
  • 1
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
  • Thank you for the response. I think I asked something that I was not quite looking for, I edited my quesiton. My service does not seem to care about the IsRequired attribute set on my objects propereties. I am not sure why that could be? – Nick LaMarca Apr 25 '12 at 18:05
  • @NickLaMarca See [this related SO post](http://stackoverflow.com/a/3436039/175679) on how to enforce required parameters by controlling the generated WSDL. `IsRequired` only marks `minOccurs="0"` in the generated XSD. – SliverNinja - MSFT Apr 25 '12 at 18:43