问题
Possible Duplicate:
RESTful Workflow Service Endpoints in WF4 / WCF
I am trying to make Windows Workflow Services 4.0 work with a REST interface. I have a very simple workflow service called "Service1" with a receiveRequest and sendResponse activity.
By default WF Services autogenerate the classes and interfaces implemented, however i would like to force the WF Service to use my own REST enabled interface instead of some internal autogenerated interface.
The interface would be the following:
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke( UriTemplate = "/Data/{item}", Method = "GET" )]
String GetData( Int32 item );
}
However, i have difficulties configuring the XAML to work with this interface. I would need a XAML configuration like this to specify that the Service contract name is my own contract:
<Receive x:Name="__ReferenceID0" CanCreateInstance="True" DisplayName="ReceiveRequest" sap:VirtualizedContainerService.HintSize="464,90" OperationName="GetData" ServiceContractName="w:IService">
However when i run this workflow service i get the following exception:
The contract name 'wfService.IService' could not be found in the list of contracts implemented by the service 'Service1'.
However, the service that gets created behind the scenes does not implement the IService interface and i would like to know how can i extend the service that gets instantiated by the workflow engine to implement my own interface (which i described above)?
Thanks
回答1:
In WF4 you cannot declare ServiceContract in code and use it. Contract is declared in XAML and WorkflowServiceHost generates endpoint from declaration.
To enable REST for for your workflowservice you have few options:
- Use HttpWorkflowHost from http://wf.codeplex.com/wikipage?title=WebAPIWorkflow. Limitation is that then you will have only REST.
- Do something similar to this: http://msdn.microsoft.com/en-us/library/aa967564.aspx Differences are: replace WorkflowFormatterBehavior instead of DataContractSerializerOperationBehavior, arguments are extracted from message contract instead of operation contract and keep in mind that you will not have client part of this example and you will have to format response according to protocol.
来源:https://stackoverflow.com/questions/11612278/wcf-workflow-service-rest-interface