Skip to main content
評価してください: 

WCF/WF 統合サービスの作成

 スクリーンキャスト


このデモの内容


ここでは、WCF (Windows Communication Foundation) と WF (Windows Wrokflow Foundation) を統合したサービスの作成方法をご紹介します。

デモでご紹介しているソースコード


【サービスのコントラクト (C#)】

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace MSFactoryService
{
    [ServiceContract]
    public interface IWorkflow1
    {
        [OperationContract]
        void Order(string productName);
        [OperationContract]
        void Create();
        [OperationContract]
        DateTime Deliver();
    }
}

【ワークフローの実装コード (C#)】

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.IO;

namespace MSFactoryService
{
    public sealed partial class Workflow1 : SequentialWorkflowActivity
    {
        public Workflow1()
        {
            InitializeComponent();
        }

        private String returnValue;
        private Int32 inputValue;

        public Int32 InputValue
        {
            get{ return inputValue; }
            set{ inputValue = value; }
        }

        public string ReturnValue
        {
            get{ return returnValue; }
            set{ returnValue = value; }
        }

        public String paramProductName = default(System.String);
        public DateTime paramReturnValue = default(System.DateTime);

        private void codeActivity1_ExecuteCode(object sender, EventArgs e)
        {
            using (FileStream fs = File.Create(Path.Combine(@"c:\tmp", paramProductName + "_ordered.txt")))
            {
                // 何も処理しない
            }
        }

        private void codeActivity2_ExecuteCode(object sender, EventArgs e)
        {
            using (FileStream fs = File.Create(Path.Combine(@"c:\tmp", paramProductName + "_created.txt")))
            {
                // 何も処理しない
            }

        }

        private void codeActivity3_ExecuteCode(object sender, EventArgs e)
        {
            using (FileStream fs = File.Create(Path.Combine(@"c:\tmp", paramProductName + "_delivered.txt")))
            {
                // 何も処理しない
            }
            paramReturnValue = DateTime.Now;
        }
    }
}

【ホスティングのマークアップ (.svc)】

<%@ ServiceHost Language="C#" Debug="true" Service="MSFactoryService.Workflow1" Factory="System.ServiceModel.Activation.WorkflowServiceHostFactory" %>

【サービスの構成 (web.config)】

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  . . . 中略 . . .

  <system.serviceModel>
    <services>
      <service name="MSFactoryService.Workflow1" behaviorConfiguration="MSFactoryService.Service1Behavior">
        <endpoint address="" binding="wsHttpContextBinding" contract="MSFactoryService.IWorkflow1"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MSFactoryService.Service1Behavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

前のページへ戻る


ページのトップへ