In the previous two articles, we have already introduced how to mobilize Workflow workflows in Web services. In this article, we will introduce how to use InvokeWebServiceActivity to mobilize Web Services in Workflow.
The following uses the simplest Hello World as an example:
First, develop an ASMX Service
View Code
<% @ WebService Language = "C #" CodeBehind = "~ /App_Code/WebServiceForWorkflow. cs "class =" WebServiceForWorkflow "%>
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
// To allow ASP. net ajax to call this Web service from a script, cancel the comments to the downstream.
// [System. Web. Script. Services. ScriptService]
Public class WebServiceForWorkflow: System. Web. Services. WebService {
Public WebServiceForWorkflow (){
// If you use the designed component, uncomment the following line
// InitializeComponent ();
}
[WebMethod]
Public string HelloWorld (){
Return "Hello World ";
}
}
Then add the InvokeWebServiceActivity activity to the Workflow file.
Now, you can use the URL attribute to add the reference "http: // localhost: 5500" to the Web service.
/WebServiceForWorkflow. asmx ", the system automatically generates a proxy to manage the service. Set MethodName
HelloWorld, set ReturnValue to data.
Finally, add the processing method invokeWebServiceActivity1. invokewebserviceactivity=invoked
View Code
namespace Microsoft.Workflow
{
public sealed partial class Workflow3 : SequentialWorkflowActivity
{
public string data;
public Workflow3()
{
InitializeComponent();
}
private void invokeWebServiceActivity1_Invoked(object sender, InvokeWebServiceEventArgs e)
{
Console.WriteLine(data);
}
}
}
Configure the config file.
View Code
<? Xml version = "1.0" encoding = "UTF-8"?>
<Configuration>
<ConfigSections>
<SectionGroup name = "applicationSettings" type = "System. Configuration. ApplicationSettingsGroup, System, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089">
<Section name = "Microsoft. workflow. properties. settings "type =" System. configuration. clientSettingsSection, System, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089 "requirePermission =" false "/>
</SectionGroup>
</ConfigSections>
<ApplicationSettings>
<Microsoft. Workflow. Properties. Settings>
<Setting name = "Microsoft_Workflow_WebServiceForWorkflow"
SerializeAs = "String">
<Value> http: // localhost: 5500/WebServiceForWorkflow. asmx </value>
// Here is the reference address of the Web service
</Setting>
</Microsoft. Workflow. Properties. Settings>
</ApplicationSettings>
</Configuration>
Now you can perform a test on Workflow.
View Code
static void Main(string[] args)
{
using (WorkflowRuntime runtime = new WorkflowRuntime())
{
runtime.StartRuntime();
WorkflowInstance instance = runtime.CreateWorkflow(typeof(Workflow3), null);
instance.Start();
AutoResetEvent wailHandler = new AutoResetEvent(false);
wailHandler.WaitOne(1000);
Console.ReadLine();
}
}
Through this development instance, you can realize how to use InvokeWebServiceActivity to call Web Services. All in all, through the Web Service and
Workflow workflows can be called to develop complex business layers. In the next article, we will introduce how to implement mutual calls between the WCF and Workflow workflows,
Coordinate the work.
Mutual invocation of WF workflows and Web Services -- call Workflow workflows (Basic instances) through Web Services)
Mutual invocation of WF workflows and Web Services -- call Workflow workflows through Web Services (develop persistent workflows)
Mutual invocation of WF workflows and Web Services -- using InvokeWebServiceActivity to call Web Services in Workflow workflows
Mutual invocation of WF workflows and Web Services -- mutual invocation of WF and WCF (publishing WF as WCF using ReceiveActivity)