How to Associate an Activity with a Service Contract?
After you have created the service interface, you can then add the ReceiveActivity activity to the workflow and configure it to respond to method invocations on the service process.
To associate an activity with a service contract:
- Add a reference to the class library.
- Add a ReceiveActivity activity to a workflow.
- Set the ServiceOperationInfo property to an operation on the service.
- Bind input and output parameters to fields in the workflow.
When you specify the ServiceOperationInfo property, Visual Studio adds code to the workflow designer file to create new properties for the ReceiveActivity activity. This enables you to bind the input parameters and return value to workflow member variables if necessary.
Note: Note that, when you publish a workflow in a service, you do not specify a ChannelToken object because the service and workflow are in the same process. Therefore, they do not use remote communication.
For example, consider a service library, ContosoMovies, that contains the ContosoMovieTicketBooking service interface. The service contains an operation, acquireTickets, that is invoked after the user has specified the number of tickets that are required for a specific film. To implement functionality for this operation in a workflow activity, you first need to add a reference to the ContosoMovies library. When you have added the reference, you add a ReceiveActivity activity to the workflow. You then use the ReceiveActivity ServiceOperationInfo property to select the ContosoMovieTicketBooking interface and then select the acquireTickets operation in that service. Visual Studio updates the activity properties to include any parameter information that is expected from the client application, so that you can use that data when you implement the service functionality.
For more information about ReceiveActivity, see ReceiveActivity Class