如何将Windows Workflow作为Web服务(.svc)托管?
发布时间:2020-05-22 12:27:30 所属栏目:Windows 来源:互联网
导读:我正在尝试将 Windows工作流程作为Web服务托管,下面是我构建的示例工作流程,并希望作为Web服务(.svc)托管,是否可以建议所需的步骤? using System;using System.ServiceModel.Activities;using System.Activities;using System.ServiceModel;using System.Act
|
我正在尝试将 Windows工作流程作为Web服务托管,下面是我构建的示例工作流程,并希望作为Web服务(.svc)托管,是否可以建议所需的步骤? using System;
using System.ServiceModel.Activities;
using System.Activities;
using System.ServiceModel;
using System.Activities.Statements;
namespace DemoWF
{
public class _25_LeaveRequest
{
public WorkflowService GetInstance()
{
WorkflowService service;
Variable<int> empID = new Variable<int> { Name = "empID" };
Variable<int> requestID = new Variable<int> { Name = "requestID" };
Receive receiveLeaveRequest = new Receive
{
ServiceContractName = "ILeaveRequestService",OperationName = "ApplyLeave",CanCreateInstance = true,Content = new ReceiveParametersContent
{
Parameters ={
{"empID",new OutArgument<int>(empID)}
}
}
};
SendReply replyLeaveRequestID = new SendReply
{
Request = receiveLeaveRequest,Content = new SendParametersContent
{
Parameters ={
{"requestID",new InArgument<int>(requestID)},},};
Sequence workflow = new Sequence()
{
Variables = { empID,requestID },Activities = {
new WriteLine{Text="WF service is starting..."},receiveLeaveRequest,new WriteLine{
Text=new InArgument<string>(aec=> "Emp ID="+empID.Get(aec).ToString())
},new Assign<int>{
Value=new InArgument<int>(5),To=new OutArgument<int>(requestID)
},new WriteLine{
Text=new InArgument<string>(aec=> "Request ID="+requestID.Get(aec).ToString())
},replyLeaveRequestID
},};
service = new WorkflowService
{
Name = "AddService",Body = workflow
};
return service;
}
}
现在,它是自我托管的,如下所示 namespace DemoWF
{
class Program
{
static void Main(string[] args)
{
LeaveRequest();
}
private static void LeaveRequest()
{
_25_LeaveRequest receiveAndReplyWorkflow = new _25_LeaveRequest();
WorkflowService wfService = receiveAndReplyWorkflow.GetInstance();
Uri address = new Uri("http://localhost:8000/WFServices");
WorkflowServiceHost host = new WorkflowServiceHost(wfService,address);
try
{
Console.WriteLine("Opening Service...");
host.Open();
Console.WriteLine("WF service is listening on " + address.ToString() + ",press any key to close");
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("some thing bad happened" + e.StackTrace);
}
finally
{
host.Close();
}
}
}
}
最快的方法是创建WCF工作流服务应用程序.
您将获得一个工作流设计器,您可以在其中拖放所需的活动: 如果您在Visual Studio中运行该项目,您将获得一个自动生成的WSDL与您的服务操作: 它还将调出Visual Studio的WCF测试客户端工具: 您可以使用“Pick Branch”活动创建一个基于工作流的服务来处理多种方法.然后,每个分支将具有“接收和发送回复”活动,其中接收活动移动到触发部分,并且动作部分中的发送回复活动. 每个触发器都用于服务的特定操作.在下面的示例中,我定义了两个操作:MyFirstOperation和MySecondOperation. 以下是WCF测试客户端工具将显示的工作流程中显示的多个操作: 希望这能让你开始.站起来基于工作流程的WCF服务的主题可以非常复杂. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 09、组策略之软件分发(01-02)
- Windows下的PHP 5.3.x安装 Zend Guard Loader教程
- windows-phone-8 – Windows Phone 8.1应用程序无法在模拟器
- windows – sqlite3-ruby gem:无法构建gem本机扩展名
- windows – 在matlab中监视内存
- Windows下动态加载的库的地址范围
- BAT脚本编写教程(比较易懂和全面)
- Windows上Jenkins的git插件不使用带子模块的凭据
- ssms – 使用Windows身份验证时,如何在SQL Server Manageme
- macos – 如何使用AFP将Windows客户端连接到OSX服务器
推荐文章
站长推荐
- win10远程桌面连接win2012 错误
- windows – 如何在git bash中注册新安装的驱动器
- 在Windows XP上安装后,Python无法看到加密模块
- Windows Azure Powershell部署错误 – “远程服务
- 如何控制Windows中打印机的打印机托盘选择
- windows-installer – installshield和windowsin
- xaml – 如何在关闭时为SettingsFlyout设置动画
- Windows下利用Gvim写PHP产生中文乱码问题解决方法
- 在Windows上使用TortoiseSVN更改文件名大小写
- Windows下的PHP安装文件线程安全和非线程安全的区
热点阅读
