Defining Request and Response Messages
Any operation that you define in a DCS service requires a request message object and can also contain an optional response message object. A client application creates an instance of the request object, populates it with data, and passes it as a parameter to the operation when the client application invokes the service. The DCS operation receives the request object, processes it, and (optionally) formats a response that it returns to the client application.
Note
When you implement an operation, the code that the DCS Software Factory generates automatically includes Request and Response properties. These properties expose the request and response message instances that are passed to and from the operation. This lets you access the messages in your workflow that implement the operation.
You can implement message classes in two ways:
- You can create a central Messages project manually, define all message classes in the Messages project, and then compile the project as an assembly. After you compile the project, add a reference to the assembly to every service that requires the messages.
- You can use Visual Studio to generate message classes for each operation definition in the assembly that defines service operations. Messages are created in namespaces based on the operation name. Therefore, you must reference each namespace that contains the message classes that you require, rather than referencing a single, central message namespace.
To create a central Messages project
In your DCS Solution project, right-click the Messages folder, point to Add, and then click Messages.
A wizard starts, which will assist you in creating the Messages project.
In the Add New Project dialog box, select the Message project type, provide a name and location for the project, and then click OK.
In the Configure Project dialog box, provide a suitable namespace for the Messages project, and then click Finish.
After you create the Messages project, you can add classes to it that define request and response messages.
To add a message class to the central message project
Right-click the message project, and then click Add Message Class.
In the Add Message Class dialog box, type a name for the message class, and then click Finish.
-
Note
When messages are created, it is common practice to add Request or Response to message names as suffixes, depending on the intended direction of the message. Incoming messages are request messages to the service, and outgoing messages are response messages.
In Solution Explorer, double-click the source code file for the message to open the message class in the Code and Text editor.
Add properties and methods that define the data and functionality of the message class.
-
Note
To enable the serializer to understand that the property requires serialization before it sends the message, you should decorate any properties that require serialization with the DataMember attribute.
When you complete the customization of the message class, save the file.
Continue adding message classes until you have all of the message classes that you require.
To generate message classes in the operation assembly
In the Add Operation dialog box for any of the workflow models, on the Messages Selector page, clear the Select messages from assemblies check box, and then click Next. Click Finish to complete the dialog and generate the template operation files.
In the Operation folder, open the Messages folder and examine the files inside. Visual Studio generates Request, Response, Error, and Exception classes, based on the operation name that you provide in the dialog.
In Solution Explorer, double-click the source code file for the message to open the message class in the Code and Text editor.
Add properties and methods that define the data and functionality of the message class.
-
Note
To enable the serializer to understand that the property should be serialized before it sends the message, you should decorate any properties that require serialization with the DataMember attribute.
When you complete the customization of the message class, save the file.
When you complete the customization of the messages classes that you require, build the project and verify that there are no errors.