Service constraints - Demonstration

In the following demonstration, some imaginary yearly financial data is collected.

The YearlyIncome needs to be specified, as well the month of the maximal and minimal incomes.

In case of the MaxMonthlyIncome and MinMonthlyIncome, the month number and the income must be provided.

For the data to be valid, these conditions need to be fulfilled:

  • (1) The maximal monthly income must be lower than the minimal monthly income
  • (2) The maximal monthly income must be higher than the average monthly income (yearly income / 12)
  • (3) The minimal monthly income must be lower than the average monthly income (yearly income / 12)

Those 3 conditions are checked using two ServiceConstraints:

  • CheckMaxMonthlyIncome checks conditions (1) and (2) within the MaxMonthlyIncome/Value field
  • CheckMinMonthlyIncome checks conditions (1) and (3) within the MinMonthlyIncome/Value field
 
Financial Statistics
Yearly Income
Max Monthly Income
Value
Month
12
Min Monthly Income
Value
Month
12
XML output

        
Service constraints - Description

Sometimes it is desirable to check validity of the given filed on the server side.

This is possible with the use of the ServiceConstraint control.

The ServiceConstraint sends a web request to the server, with the defined parameters, and returns either true or false.

To specify the address of the webservice, use the ServicePath property.

To specify the name of the webmethod, use the ServiceMethod property.

The service parameter

The parameters that are sent to the webservice are defined as inner content properties with the use of the ServiceParameter control.

The ServiceParameter control should be defined with the use of the following properties:

  • Name - the name of the variable, used in the webmethod
  • Path - the xpath-like path to the MForm item, whose value will be sent
The webmethod

The server-side webmethod must contain the [ScriptMethod] attribute, and the class that this webmethod is within must contain the [ScriptService] attribute.

The definition of this method must match the definition of the ServiceConstraint control:

  • The name of the method must match the value of the ServiceMethod property
  • The order of the ServiceParameter properties must match the order of method variables
  • The name of the ServiceParameter property must match the name of the corresponding method variable
  • The ServiceParameter value must be serializable with the use of its corresponding method's type
Example:
If the definition of the ServiceConstraint looks like this:
<mfadd:ServiceConstraint runat="server" ServicePath="some/service/path" ServiceMethod="MethodName" >
            <mfadd:ServiceParameter runat="server" Name="someParameter" Path="some/parameter/path" />
            <mfadd:ServiceParameter runat="server" Name="otherParameter" Path="other/parameter/path" />
</mfadd:ServiceConstraint>
                
then the method's definition should look like this:
        [ScriptMethod]
        public bool MethodName(someType someParameter, otherType otherParameter) {
            ...
        }