8

WF4(RC)サービスを動的にホストしようとしています。2つのプロジェクトでテストソリューションがあります。1つ目は、1つのルートフローチャートアクティビティと単純なカスタムコードアクティビティを含む宣言型ワークフローサービスライブラリです。ワークフローサービスライブラリは、他のカスタムアセンブリや参照に依存しません。2つ目は、ホストアプリです。これは、テストソリューションでは単なるコンソールアプリケーションです。

ホストアプリで、ActivityXamlServicesを使用してワークフローサービスのXamlをアクティビティにロードし、WorkflowServiceHostを使用してそのアクティビティを使用してワークフローインスタンスを起動しようとしています。

WorkflowServiceHostオブジェクトを新しくしようとするとすぐに、この例外が発生します...

不明なタイプ'{clr-namespace:DeclarativeServiceLibrary1}CodeActivity1'を作成できません。

フローチャートデザイナからCodeActivity1を削除すると、すべてが正常に実行されます。ホストプロジェクトからワークフローサービスプロジェクトへの直接参照を追加し、Xamlから作成されたアクティビティではなく、フローチャートアクティビティのインスタンスを使用してWorkflowServiceHostを作成すると、正常に機能します。

動的にロードされたときに、何らかの理由でCodeActivityを使用するのは好きではないようです。

ワークフローサービスを動的に作成できない理由について誰かが考えていますか?

私のコードは次のとおりです...

DeclarativeServiceLibrary1.Activity1.xaml..。

<Activity mc:Ignorable="sap" x:Class="DeclarativeServiceLibrary1.Activity1" sap:VirtualizedContainerService.HintSize="654,676" mva:VisualBasic.Settings="Assembly references and imported namespaces for internal implementation" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:av="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:local="clr-namespace:DeclarativeServiceLibrary1" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:st="clr-namespace:System.Text;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Flowchart sad:XamlDebuggerXmlReader.FileName="C:\dev\test\MyWorkflow\DeclarativeServiceLibrary1\Activity1.xaml" sap:VirtualizedContainerService.HintSize="614,636">
    <sap:WorkflowViewStateService.ViewState>
      <scg3:Dictionary x:TypeArguments="x:String, x:Object">
        <x:Boolean x:Key="IsExpanded">False</x:Boolean>
        <av:Point x:Key="ShapeLocation">270,2.5</av:Point>
        <av:Size x:Key="ShapeSize">60,75</av:Size>
        <av:PointCollection x:Key="ConnectorLocation">300,77.5 300,107.5 300,165</av:PointCollection>
      </scg3:Dictionary>
    </sap:WorkflowViewStateService.ViewState>
    <Flowchart.StartNode>
      <FlowStep x:Name="__ReferenceID0">
        <sap:WorkflowViewStateService.ViewState>
          <scg3:Dictionary x:TypeArguments="x:String, x:Object">
            <av:Point x:Key="ShapeLocation">172.5,165</av:Point>
            <av:Size x:Key="ShapeSize">255,90</av:Size>
            <av:PointCollection x:Key="ConnectorLocation">300,255 300,285 300,299.5</av:PointCollection>
          </scg3:Dictionary>
        </sap:WorkflowViewStateService.ViewState>
        <p:Receive CanCreateInstance="True" sap:VirtualizedContainerService.HintSize="255,90" OperationName="MyOperation" ServiceContractName="MyContractName" />
        <FlowStep.Next>
          <FlowStep x:Name="__ReferenceID1">
            <sap:WorkflowViewStateService.ViewState>
              <scg3:Dictionary x:TypeArguments="x:String, x:Object">
                <av:Point x:Key="ShapeLocation">194.5,299.5</av:Point>
                <av:Size x:Key="ShapeSize">211,61</av:Size>
                <av:PointCollection x:Key="ConnectorLocation">300,360.5 300,390.5 300,399</av:PointCollection>
              </scg3:Dictionary>
            </sap:WorkflowViewStateService.ViewState>
            <WriteLine sap:VirtualizedContainerService.HintSize="211,61" Text="Workflow started" />
            <FlowStep.Next>
              <FlowStep x:Name="__ReferenceID3">
                <sap:WorkflowViewStateService.ViewState>
                  <scg3:Dictionary x:TypeArguments="x:String, x:Object">
                    <av:Point x:Key="ShapeLocation">200,399</av:Point>
                    <av:Size x:Key="ShapeSize">200,22</av:Size>
                    <av:PointCollection x:Key="ConnectorLocation">300,421 300,451 300,479.5</av:PointCollection>
                  </scg3:Dictionary>
                </sap:WorkflowViewStateService.ViewState>
                <local:CodeActivity1 sap:VirtualizedContainerService.HintSize="200,22" />
                <FlowStep.Next>
                  <FlowStep x:Name="__ReferenceID2">
                    <sap:WorkflowViewStateService.ViewState>
                      <scg3:Dictionary x:TypeArguments="x:String, x:Object">
                        <av:Point x:Key="ShapeLocation">194.5,479.5</av:Point>
                        <av:Size x:Key="ShapeSize">211,61</av:Size>
                      </scg3:Dictionary>
                    </sap:WorkflowViewStateService.ViewState>
                    <WriteLine sap:VirtualizedContainerService.HintSize="211,61" Text="The code activity worked!" />
                  </FlowStep>
                </FlowStep.Next>
              </FlowStep>
            </FlowStep.Next>
          </FlowStep>
        </FlowStep.Next>
      </FlowStep>
    </Flowchart.StartNode>
    <x:Reference>__ReferenceID0</x:Reference>
    <x:Reference>__ReferenceID1</x:Reference>
    <x:Reference>__ReferenceID2</x:Reference>
    <x:Reference>__ReferenceID3</x:Reference>
  </Flowchart>
</Activity>

DeclarativeServiceLibrary1.CodeActivity1.cs..。

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

namespace DeclarativeServiceLibrary1
{

    public sealed class CodeActivity1 : CodeActivity
    {
        // Define an activity input argument of type string
        //public InArgument<string> Text { get; set; }

        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            //string text = context.GetValue(this.Text);
        }
    }
}

DeclarativeServiceLibrary1.Web.Config..。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

ConsoleApplication1.Program.cs..。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.Activities.XamlIntegration;
using System.ServiceModel;
using System.ServiceModel.Activities;
using System.ServiceModel.Description;
using System.Xaml;
using System.Reflection;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {            
            string baseAddress = @"http://localhost:8081/MyContractName";

            string curDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string wfDefPath =  Path.Combine(curDir, "Activity1.xaml");

            Activity workflowActivity = (Activity)ActivityXamlServices.Load(wfDefPath); 
            WorkflowService service = new WorkflowService { Body = workflowActivity }; 
            Uri serviceUri = new Uri(baseAddress, UriKind.Absolute); 
            WorkflowServiceHost host = new WorkflowServiceHost(service, new Uri[] { serviceUri }); 
            host.Open();

            //Display that we are listening on the console window
            Console.WriteLine("Workflow '{0}' is listening at '{1}'", host.Activity.DisplayName, baseAddress);
            Console.ReadLine();
        }
    }
}

delarativeワークフローサービスライブラリにビルド後のイベントがあり、アセンブリとXamlファイルをホストコンソールアプリのbin \debug\フォルダーにコピーします。

4

4 に答える 4

12

簡単な答え-Xamlロードはローカル(デフォルト)アセンブリを推測できないため、XamlReaderSettings.LocalAssemblyで指定する必要があります。

于 2010-02-26T09:33:30.113 に答える
9

アクティビティのオープンソースコード。「xmlns:local = "clr-namespace:DeclarativeServiceLibrary1"をxmlns:local = "clr-namespace:DeclarativeServiceLibrary1; assembly=DeclarativeServiceLibrary1"に変更します。

于 2010-05-05T08:58:42.807 に答える
0

xamlファイルを直接逆シリアル化していますが、CLR型としてDeclarativeServiceLibrary1アセンブリにコンパイルされた型(CodeActivity1)を参照しています。最も明白な答えは、DeclarativeServiceLibrary1アセンブリは実行時にコンソールアプリで使用できないということです。このアセンブリがコンソールアプリを実行しているフォルダー(\ bin \ debug)にコピーされていることを確認し、それが違いを生むかどうかを確認します。

つまり、xamlファイルを直接読み取っている場合でも、参照するすべての型にアクセスする必要があります。

于 2010-02-25T13:45:22.313 に答える
0

コードを見ると、単純なアクティビティではなく、WorkflowServiceをロードする必要があることがわかります。ここで試すには、基本的に2つのオプションがあります。

オプション1:アクティビティをロードし、生成されたワークフローサービス内でホストします。

これを行うには、通常どおりアクティビティをロードし、次のスニペットを使用してワークフローサービスインスタンスにします。

WorkflowService service = new WorkflowService();
service.Body = loadedActivity;

その後、ワークフローサービスホスト内でホストできます。

オプション2:ワークフローサービスを直接ロードする

2番目のオプションは、現在のオプションとそれほど変わりません。ただし、ActivityXamlServicesクラスを使用する代わりに、XamlServicesクラスを使用してワークフローサービスをロードする必要があります。その後、サンプルで使用した設定でワークフローサービスホストを起動します。

于 2010-02-25T19:27:44.883 に答える