WCF工作流服务REST接口 [英] WCF Workflow Service REST interface

查看:112
本文介绍了WCF工作流服务REST接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
WF4/WCF中的RESTful工作流服务端点

Possible Duplicate:
RESTful Workflow Service Endpoints in WF4 / WCF

我正在尝试使Windows Workflow Services 4.0与REST界面一起使用.我有一个非常简单的工作流服务,称为"Service1",具有receiveRequest和sendResponse活动.

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.

默认情况下,WF Services自动生成实现的类和接口,但是我想强制WF Service使用我自己的REST支持的接口,而不是某些内部自动生成的接口.

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.

界面如下:

[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebInvoke( UriTemplate = "/Data/{item}", Method = "GET" )]
    String GetData( Int32 item );
}

但是,我很难将XAML配置为与此接口配合使用. 我将需要这样的XAML配置,以指定服务合同名称是我自己的合同:

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:

在服务"Service1"实施的合同列表中找不到合同名称"wfService.IService".

The contract name 'wfService.IService' could not be found in the list of contracts implemented by the service 'Service1'.

但是,在后台创建的服务没有实现IService接口,我想知道如何扩展由工作流引擎实例化的服务以实现我自己的接口(如上所述)?

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)?

谢谢

推荐答案

在WF4中,您无法在代码中声明ServiceContract并使用它.合同在XAML中声明,WorkflowServiceHost通过声明生成终结点.

In WF4 you cannot declare ServiceContract in code and use it. Contract is declared in XAML and WorkflowServiceHost generates endpoint from declaration.

要为您的工作流服务启用REST,您有几种选择:

To enable REST for for your workflowservice you have few options:

  1. 使用 http://wf.codeplex.com/wikipage?title=WebAPIWorkflow 中的HttpWorkflowHost
  2. 一个>.局限性在于您将只有REST.
  3. 执行与此类似的操作: http://msdn.microsoft.com/zh-cn/library/aa967564.aspx 区别在于:替换WorkflowFormatterBehavior而不是DataContractSerializerOperationBehavior,从消息协定而不是操作协定中提取参数,并记住您将没有此示例的客户端部分,并且必须根据协议格式化响应.
  1. Use HttpWorkflowHost from http://wf.codeplex.com/wikipage?title=WebAPIWorkflow. Limitation is that then you will have only REST.
  2. 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.

这篇关于WCF工作流服务REST接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆