Heres the listing for the Foo Validator which validates both parameters passed to the Some ObjectFoo method

[Serializable]

class FooValidator : IParamValidator {

public bool Validate(object[] args) {

// First parameter is x. Limit it to // an integer between 0 and 9999. int x = (int)args[0];

e = "parameter 'x' exceeds maximum allowed value " + "of '9999'";

// Second parameter is y. Limit it to // an integer less than 1000. int y = (int)args[1];

e = "parameter 'y' exceeds maximum allowed value " + "of '1000'";

throw new ArgumentException

("FooValidator detected illegal parameter values\n\n" + e);

return true;

Note that we declare the validator classes with the Serializable attribute. This is because the message sink holds a reference to these classes in its _htValidators member. Because the runtime marshals the envoy sink chain to the client in the Envoylnfo property of the ObjRef, any message sink members must also be Serializable. You'll also want to keep them lightweight to minimize the transmission cost during marshaling across the .NET Remoting boundary.

0 0

Post a comment