1. Implement the replaced class
- Go to the Configuration section and select a custom package to which to add the schema.
-
Click Add → Source code on the section list toolbar.
-
Fill out the schema properties in the Schema Designer:
- Code – "UsrOriginalClass".
- Title – "OriginalClass".
-
Create a replaced UsrOriginalClass class that contains the GetAmount(int, int) virtual method. The method adds two values passed as parameters.
- Click Save then Publish on the Designer's toolbar.
2. Implement a replacing class
- Go to the Configuration section and select a custom package to which to add the schema. Select a package other than the package in which you implemented the UsrOriginalClass replaced class.
- Add the custom package that contains the UsrOriginalClass replaced class as a dependency for the custom package that contains the replacing class.
-
Click Add → Source code on the section list toolbar.
-
Fill out the schema properties in the Schema Designer:
- Code – "UsrSubstituteClass".
- Title – "SubstituteClass".
-
Create a SubstituteClass replacing class that contains the GetAmount(int, int) method. The method summarizes two values passed as parameters and multiplies the sum by the value passed in the Rate property. Creatio will initialize the Rate property in the replacing class constructor.
- Click Save then Publish on the Designer's toolbar.
3. Implement a custom web service
- Go to the Configuration section and select a custom package to which to add the schema. Use the package in which you implemented the UsrOriginalClass replaced class for the custom web service.
-
Click Add → Source code on the section list toolbar.
-
Fill out the schema properties in the Schema Designer:
- Code – "UsrAmountService".
- Title – "AmountService".
-
Create a service class.
- Add the Terrasoft.Configuration namespace in the Schema Designer.
- Add the namespaces the data types of which to utilize in the class using the using directive.
- Add the name of the UsrAmountService class that matches the schema name (the Code property).
- Specify the Terrasoft.Nui.ServiceModel.WebService.BaseService class as a parent class.
- Add the [ServiceContract] and [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] attributes to the class.
-
Implement a class method.
Add the public string GetAmount(int value1, int value2) method that implements the endpoint of the custom web service to the class in the Schema Designer. The GetAmount(int, int) method adds two values passed as parameters.
View the source code of the UsrAmountService custom web service below.
The code provides examples of creating a replacing class both using the replaced objects factory and using the new() operator.
- Click Save then Publish on the Designer's toolbar.
As a result, Creatio will add the custom UsrAmountService REST web service that has the GetAmount endpoint.
Outcome of the example
To call the custom web service, access the GetAmount endpoint of the UsrAmountService web service in the browser and pass 2 arbitrary numbers as value1 and value2 parameters.
The GetAmountResult property will return the custom web service results executed both using and not using the class replacement.
