-1
  1. リスト項目

1.> 新しいプラグインを作成しました (任意のカスタム エンティティ (仮に ce1) の作成および更新時に起動されます)

2.>オンライン版に登録。

3.>そのプラグインは、ワークフロー(C#コードを使用したシステムxamlワークフロー)を作成し、そのWFもアクティブにします。

4.>F9 を作成するその WF..:)

5.>問題は...:(

6.> 別の C# アプリを使用する WF がオンライン バージョンでアクティブ化されずに作成されるだけである (つまり、WF がドラフト モードである)

7.>ただし、オンプレミス版では f9 で動作しています。

8.> オンラインでも f9 で動作していますが、CRM インターフェイスを使用しています。

9.> C# アプリケーションを使用すると、その WF がアクティブ化される行でエラーがスローされます...エラーは: 偽装時にワークフローを発行できません。

どんな種類の助けも大歓迎です...助けてください...

ありがとう。

4

2 に答える 2

0
//Getting Service as happens in PLUGIN
IOrganizationServiceFactory serviceFactory =          (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
  IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

//Configuring xaml to create workflow    

 string xamlWfPrefix = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Activity x:Class=""XrmWorkflow"" 
xmlns=""http://schemas.microsoft.com/netfx/2009/xaml/activities"" 
xmlns:mva=""clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35""
xmlns:mxs=""clr-namespace:Microsoft.Xrm.Sdk;assembly=Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"" 
xmlns:mxswa=""clr-namespace:Microsoft.Xrm.Sdk.Workflow.Activities;assembly=Microsoft.Xrm.Sdk.Workflow, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35""
xmlns:s=""clr-namespace:System;assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" 
xmlns:scg=""clr-namespace:System.Collections.Generic;assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" 
xmlns:srs=""clr-namespace:System.Runtime.Serialization;assembly=System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089""
xmlns:this=""clr-namespace:"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
  <x:Members>
    <x:Property Name=""InputEntities"" Type=""InArgument(scg:IDictionary(x:String, mxs:Entity))"" />
    <x:Property Name=""CreatedEntities"" Type=""InArgument(scg:IDictionary(x:String, mxs:Entity))"" />
  </x:Members>
  <this:XrmWorkflow.InputEntities>
    <InArgument x:TypeArguments=""scg:IDictionary(x:String, mxs:Entity)"" />
  </this:XrmWorkflow.InputEntities>
  <this:XrmWorkflow.CreatedEntities>
    <InArgument x:TypeArguments=""scg:IDictionary(x:String, mxs:Entity)"" />
  </this:XrmWorkflow.CreatedEntities>
  <mva:VisualBasic.Settings>Assembly references and imported namespaces for internal implementation</mva:VisualBasic.Settings>
  <mxswa:Workflow>
    <Sequence DisplayName=""CreateStep1"">
      <Sequence.Variables>
        <Variable x:TypeArguments=""x:Object"" Name=""CreateStep1_1"" />
        <Variable x:TypeArguments=""x:Object"" Name=""CreateStep1_2"" />
      </Sequence.Variables>
      <Assign x:TypeArguments=""mxs:Entity"" To=""[CreatedEntities(&quot;CreateStep1_localParameter#Temp&quot;)]"" Value=""[New Entity(&quot;new_crm_new_sfeed&quot;)]"" />
      <mxswa:ActivityReference AssemblyQualifiedName=""Microsoft.Crm.Workflow.Activities.EvaluateExpression, Microsoft.Crm.Workflow, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"" DisplayName=""EvaluateExpression"">
        <mxswa:ActivityReference.Arguments>
          <InArgument x:TypeArguments=""x:String"" x:Key=""ExpressionOperator"">CreateCrmType</InArgument>
          <InArgument x:TypeArguments=""s:Object[]"" x:Key=""Parameters"">[New Object() { Microsoft.Xrm.Sdk.Workflow.WorkflowPropertyType.String, """;

                    xamlWfPrefix += displayname + @""", ""String"" }]</InArgument>
          <InArgument x:TypeArguments=""s:Type"" x:Key=""TargetType"">
            <mxswa:ReferenceLiteral x:TypeArguments=""s:Type"" Value=""x:String"" />
          </InArgument>
          <OutArgument x:TypeArguments=""x:Object"" x:Key=""Result"">[CreateStep1_1]</OutArgument>
        </mxswa:ActivityReference.Arguments>
      </mxswa:ActivityReference>
      <mxswa:SetEntityProperty Attribute=""new_name"" Entity=""[CreatedEntities(&quot;CreateStep1_localParameter#Temp&quot;)]"" EntityName=""new_crm_new_sfeed"" Value=""[CreateStep1_1]"">
        <mxswa:SetEntityProperty.TargetType>
          <InArgument x:TypeArguments=""s:Type"">
            <mxswa:ReferenceLiteral x:TypeArguments=""s:Type"" Value=""x:String"" />
          </InArgument>
        </mxswa:SetEntityProperty.TargetType>
      </mxswa:SetEntityProperty>
      <mxswa:ActivityReference AssemblyQualifiedName=""Microsoft.Crm.Workflow.Activities.EvaluateExpression, Microsoft.Crm.Workflow, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"" DisplayName=""EvaluateExpression"">
        <mxswa:ActivityReference.Arguments>
          <InArgument x:TypeArguments=""x:String"" x:Key=""ExpressionOperator"">CreateCrmType</InArgument>
          <InArgument x:TypeArguments=""s:Object[]"" x:Key=""Parameters"">[New Object() { Microsoft.Xrm.Sdk.Workflow.WorkflowPropertyType.String, """;

                    xamlWfPrefix += displayname;

                    string xamlWfSuffix = @", ""String"" }]</InArgument>
          <InArgument x:TypeArguments=""s:Type"" x:Key=""TargetType"">
            <mxswa:ReferenceLiteral x:TypeArguments=""s:Type"" Value=""x:String"" />
          </InArgument>
          <OutArgument x:TypeArguments=""x:Object"" x:Key=""Result"">[CreateStep1_2]</OutArgument>
        </mxswa:ActivityReference.Arguments>
      </mxswa:ActivityReference>
      <mxswa:SetEntityProperty Attribute=""new_description"" Entity=""[CreatedEntities(&quot;CreateStep1_localParameter#Temp&quot;)]"" EntityName=""new_crm_new_sfeed"" Value=""[CreateStep1_2]"">
        <mxswa:SetEntityProperty.TargetType>
          <InArgument x:TypeArguments=""s:Type"">
            <mxswa:ReferenceLiteral x:TypeArguments=""s:Type"" Value=""x:String"" />
          </InArgument>
        </mxswa:SetEntityProperty.TargetType>
      </mxswa:SetEntityProperty>
      <mxswa:CreateEntity EntityId=""{x:Null}"" DisplayName=""CreateStep1"" Entity=""[CreatedEntities(&quot;CreateStep1_localParameter#Temp&quot;)]"" EntityName=""new_crm_new_sfeed"" />
      <Assign x:TypeArguments=""mxs:Entity"" To=""[CreatedEntities(&quot;CreateStep1_localParameter&quot;)]"" Value=""[CreatedEntities(&quot;CreateStep1_localParameter#Temp&quot;)]"" />
      <Persist />
    </Sequence>
  </mxswa:Workflow>
</Activity>";

       //Calling method to create total xaml code that requires to create workflow
       string xamlWf = BuildWorkflowXaml(xamlWfPrefix, xamlWfSuffix, recordCreated);
        //Initiating workflow to be create
        Workflow wfOnCreate = new Workflow()
              {
                Name = "CRM_DNNWorkflow_OnCreate",
                Type = new OptionSetValue(1),
                Category = new OptionSetValue(0),
                Scope = new OptionSetValue(2),
                LanguageCode = 1033, // U.S. English
                TriggerOnCreate = true,
                OnDemand = false,
                PrimaryEntity = logicalname, //Name of entity on which WF will be fired
                Description = @"Tracks Creation",
                Xaml = xamlWf
                    };


                    xamlWf = BuildWorkflowXaml(xamlWfPrefix, xamlWfSuffix, recordDeleted);
                   //Another WF
                    Workflow wfOnDelete = new Workflow()
                    {
                        Name = "CRM_DNNWorkflow_OnDelete",
                        Type = new OptionSetValue(1),
                        Category = new OptionSetValue(0),
                        Scope = new OptionSetValue(2),
                        LanguageCode = 1033, // U.S. English
                        TriggerOnDelete = true,
                        OnDemand = false,
                        PrimaryEntity = logicalname,
                        Description = @"Tracks Deletion",
                        Xaml = xamlWf
                    };


                    xamlWf = BuildWorkflowXaml(xamlWfPrefix, xamlWfSuffix, recordModified);
                    //Another WF
                    Workflow wfOnModify = new Workflow()
                    {
                        Name = "CRM_DNNWorkflow_OnModify",
                        Type = new OptionSetValue(1),
                        Category = new OptionSetValue(0),
                        Scope = new OptionSetValue(2),
                        LanguageCode = 1033, // U.S. English
                        TriggerOnUpdateAttributeList = attributeList,
                        OnDemand = false,
                        PrimaryEntity = logicalname,
                        Description = @"Tracks Modification",
                        Xaml = xamlWf
                    };


                    workflowOnCreateId = service.Create(wfOnCreate);
                    workflowOnDeleteId = service.Create(wfOnDelete);
                    workflowOnModifyId = service.Create(wfOnModify);           

                    //activate workflow (OnCreate)
                    ActivateWorkflow(workflowOnCreateId, service, serviceProvider);

                    //activate workflow (OnDelete)
                    ActivateWorkflow(workflowOnDeleteId, service, serviceProvider);

                    //activate workflow (OnModify)
                    ActivateWorkflow(workflowOnModifyId, service, serviceProvider);
                }
            }
            catch (FaultException<OrganizationServiceFault> ex)
            {
                tracingService.Trace("Exception: {0}", ex.ToString());
                throw;
                //throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
            }
        }



        /// <summary>
        /// Builds the Xaml to define the function of a Workflow.
        /// </summary>
        /// <param name="prefix">Prefix to Xaml code</param>
        /// <param name="suffix">Suffix to Xaml code</param>
        /// <param name="status">Sets the description field of the new_crm_new_sfeed Entity</param>
        /// <returns></returns>
        private string BuildWorkflowXaml(string prefix,string suffix,string status)
        {
            return prefix + status + suffix;
        }



        /// <summary>
        /// Activates a Workflow.
        /// </summary>
        /// <param name="workflowId">Guid of the workflow to be created.</param>
        /// <param name="service">IOrganizationService Object.</param>
        private void ActivateWorkflow(Guid workflowId,IOrganizationService service,IServiceProvider serviceProvider) 
        {
            //Extract the tracing service for use in plug-in debugging.
            ITracingService tracingService =
                (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            try
            {
                SetStateRequest activateRequest = new SetStateRequest
                {
                    EntityMoniker = new EntityReference(Workflow.EntityLogicalName, workflowId),
                    State = new OptionSetValue((int)WorkflowState.Activated),
                    Status = new OptionSetValue(2)
                };
                //**Error Occurs Here**
                OrganizationResponse respActivation = service.Execute(activateRequest);
                tracingService.Trace("ActivateResponse", respActivation);
                workflowGUIDs.Add(workflowId);
            }
            catch (InvalidPluginExecutionException exe)
            {
                tracingService.Trace("Exception: {0}", exe.ToString());
                throw;
            }            
        }





**FROM MY C# APPLICATION**



// Form the RetrieveOrganization Request.
   RetrieveOrganizationRequest request = new RetrieveOrganizationRequest();
   request.UniqueName = organizationUniqueName;
   RetrieveOrganizationResponse response = (RetrieveOrganizationResponse)discoveryServiceProxy.Execute(request);

// Form the URL.
   Uri uri = new Uri(response.Detail.Endpoints[EndpointType.OrganizationService]);

 //Form the OrganizationServiceProxy Object.
   orgServiceProxy = new OrganizationServiceProxy(uri, null, discoveryServiceProxy.ClientCredentials, discoveryServiceProxy.DeviceCredentials);


Entity Dnn_selectedEntity = new Entity("new_dnn_selected_entity");
Dnn_selectedEntity["new_name"] = entityMetadataId.Value.ToString();
Dnn_selectedEntity["new_trackedentity"] = entityMetadataId.Key;
orgServiceProxy.Create(Dnn_selectedEntity);
//After Creting this record That Plugin fires....



Thanks.
于 2012-06-27T14:54:00.290 に答える
0

プラグイン コードを投稿すると役に立ちます。しかし、プラグイン コンテキストを使用して IOrganizationService を取得している場合は、偽装を使用している可能性があります。その場合は、正しい所有者で新しい OrganizationServiceProxy を作成して、問題が解決するかどうかを確認します。

私はオンライン版にアクセスできないので、これは暗闇の中の刺し傷です.

于 2012-06-26T16:33:12.977 に答える