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 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 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) {
...
}