1. Create a Source code schema
- Go to the Configuration section and select a custom package to add the schema.
-
Click Add → Source code on the section list toolbar.
-
Fill out the schema properties in the Source Code Designer:
- Set Code to "UsrEncodingService."
- Set Title to "Service with custom encoding."
Click Apply to apply the properties.
2. Create a web service class
- Go to the Schema Designer and add the namespace nested into Terrasoft.Configuration. For example, UsrEncodingServiceNamespace.
- Add the using directive to import the namespaces whose data types are utilized in the class.
- Add a class name to match 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.
- Add the SystemUserConnection system connection to enable anonymous access to the custom web service.
3. Implement a method of the web service class
- Implement the endpoint of the custom web service. To do this, add the public string Test(string Name) method to the class in the Source Code Designer. Depending on the Name parameter value specified in the ISO-8859-1 encoding and sent in the request string, the response body contains the same parameter value in the same encoding.
-
Specify the user on whose behalf to process the current HTTP request. To do this, call the SessionHelper.SpecifyWebOperationIdentity method of the Terrasoft.Web.Common namespace after retrieving SystemUserConnection. This method enables business processes to manage the database entity (Entity) from the custom web service that uses anonymous authentication.
View the source code of the UsrEncodingService custom web service below.
Click Publish on the Source Code Designer’s toolbar to apply the changes on the database level.
4 Register the web service
- Create a UsrEncodingService.svc file in the ..\Terrasoft.WebApp\ServiceModel directory.
-
Add the following record to the UsrEncodingService.svc file.
The Service attribute contains the full name of the web service class and specifies the namespace.
- Save the file.
5. Register a non-standard text encoding
- Add <customBinding> section to the ..\Terrasoft.WebApp\ServiceModel\http\bindings.config file.
-
Add the following attributes to the <customBinding> file section:
- Set the name attribute of the <binding> element to "ISO88591Encoding."
- Set the encoding attribute of the <customTextMessageEncoding> element to "ISO-8859-1."
- Set the manualAddressing attribute of the <httpTransport> element to true.
- Save the file.
- Add an identical record to the ..\Terrasoft.WebApp\ServiceModel\https\bindings.config file.
6. Enable both HTTP and HTTPS support for the web service
-
Add the following record to the ..\Terrasoft.WebApp\ServiceModel\http\services.config file.
The binding attribute contains the "<customBinding>" value that must match the name of the <customBinding> file section that registers the character encoding.
The bindingConfiguration attribute contains the name of the registered character encoding. Must match the value of the <binding> element’s name attribute specified on the previous step.
- Save the file.
- Add an identical record to the ..\Terrasoft.WebApp\ServiceModel\https\services.config file.
7. Enable access to the web service for all users
-
Add the <location> element that defines the relative path and access permissions to the web service to the ..\Terrasoft.WebApp\Web.config file.
-
Add the relative web service path to the value attribute of the <appSettings> element's AllowedLocations key in the ..\Terrasoft.WebApp\Web.config file.
- Save the file.
8. Restart Creatio in IIS
Restart Creatio in IIS to apply the changes.
Outcome of the example
Use Postman request testing tool to view the outcome of the example. Learn more about working in Postman in the official Postman documentation. Learn more about using Postman to query Creatio in a separate article: Working with requests in Postman. Learn more about using Postman to call a web service in a separate article: Call a custom web service from Postman.
To view the outcome of the example, execute a request to the UsrEncodingService web service.
Configure the request in Postman as follows:
- Specify the POST request method.
-
Specify the Test method in the request string to the UsrEncodingService custom web service.
-
Configure the request data format on the Body tab.
- Set the "raw" option.
- Select the "XML" type.
- Fill out the body of the POST request. Pass the characters in the ISO-8859-1 character encoding in the request body. Learn more about the characters the ISO-8859-1 character encoding uses in Wikipedia.
As a result, you will receive a response to the POST request. The response format is XML, the code is 200 OK. Postman will display the response body on the Body tab. The body will contain the value of the Name parameter in the ISO-8859-1 character encoding.
