Using Persistence service with .config file

May 19, 2008 at 9:14 PM
To be able to use the AdoPersistenceService in a WCF hosted worksflow in IIS I added a new constructor as
        public AdoPersistenceService(NameValueCollection parameters) :
            this(new ConnectionStringSettings(
                parameters["name"],
                parameters["connectionString"],
                parameters["providerName"] != null ? parameters["providerName"] : null
                ),
                parameters["UnLoadOnIdle"] != null ? bool.Parse(parameters["UnLoadOnIdle"]) : false,
                parameters["InstanceOwnershipDuration"] != null ? TimeSpan.Parse(parameters["InstanceOwnershipDuration"]) : TimeSpan.Zero,
                parameters["LoadInterval"] != null ? TimeSpan.Parse(parameters["LoadInterval"]) : TimeSpan.Zero
            )
        {

        }



This enabled me to use the persistence service in web.config with following settings:
        <behavior name="WebHostServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <workflowRuntime name="WorkflowsRequestActivity" validateOnCreate="true" enablePerformanceCounters="true">
            <services>
              <add type="WFTools.Services.Persistence.Ado.AdoPersistenceService, WFTools.Services" name="Oracle - ODP.NET" providerName="Oracle.DataAccess.Client" connectionString="Data Source=CT0;user id=wfp;password=wfp;" UnLoadOnIdle="True" />
            </services>
          </workflowRuntime>
        </behavior>
      </serviceBehaviors>


After the above changes all the obvious errors were removed, but I still couldn't see any activity in the persistence db. After some testing and looking around I found out that I need to turn the local transaction ON, which I did by changing the default constructor of AdoWorkBatchService to public AdoWorkBatchService() : this(true) { }
(I couldn't find any configuration setting to make this change)

I still cannot persist any workflow (The sample provided is able to persist workflows in the database).
Any help would be appreciated.

Nauman
May 20, 2008 at 6:57 PM
Found the problem when using WFTools with WCF and Web.config.
The publishers of this project might want to include the code change in the next release.

I added a new constructor for the AdoWorkBatchService that takes a NameValueCollection as a parameters and reads the value of UseLocalTransactions from the web.conig file.
    public AdoWorkBatchService(NameValueCollection parameters)
            : this(
                    parameters["UseLocalTransactions"] != null ? bool.Parse(parameters["UseLocalTransactions"]) : false
            )
        {
        }


After the above change I added this service in the WorkflowRuntime by following line in Web.config
<add type="WFTools.Services.Batching.Ado.AdoWorkBatchService, WFTools.Services" UseLocalTransactions="True" />

So the complete runtime declaration looks like:
        <behavior name="WebHostServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <workflowRuntime name="WorkflowsRequestActivity" validateOnCreate="true" enablePerformanceCounters="true">
            <services>
              <add type="WFTools.Services.Persistence.Ado.AdoPersistenceService, WFTools.Services" name="Oracle - ODP.NET" providerName="Oracle.DataAccess.Client" connectionString="Data Source=CT0;user id=wfp;password=wfp;" UnLoadOnIdle="True" />
                            <add type="WFTools.Services.Batching.Ado.AdoWorkBatchService, WFTools.Services" UseLocalTransactions="True" />
            </services>
          </workflowRuntime>
        </behavior>


Coordinator
May 30, 2008 at 12:50 AM
Hi Nauman,

Thanks for this will get it into the next release.

Dean

Jun 16, 2008 at 5:11 PM
Thanks Nauman!!! just what I needed :-)
Oct 28, 2008 at 1:42 AM
You will also need to import the "System.Collections.Specialized" namespace so you can use the NameValueCollection object :)
Jul 30, 2009 at 2:30 AM
Edited Jul 30, 2009 at 2:38 AM

I followed exact steps as described above and I'm hitting the following run-time error....does anyone know what this means or how to resolve this one?  Any help would be greatly appreciated.  Thanks.

 GenericPersistenceService::Commit - An unexpected exception occurred while performing a workflow persistence operation. System.InvalidCastException: Failed to convert parameter value from a Guid to a Byte[]. ---> System.InvalidCastException: Object must implement IConvertible.
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at System.Data.OracleClient.OracleParameter.CoerceValue(Object value, MetaType destinationType)
   --- End of inner exception stack trace ---
   at System.Data.OracleClient.OracleParameter.CoerceValue(Object value, MetaType destinationType)
   at System.Data.OracleClient.OracleParameter.SetCoercedValueInternal(Object value, MetaType metaType)
   at System.Data.OracleClient.OracleParameterBinding.PrepareForBind(OracleConnection connection, Int32& offset)
   at System.Data.OracleClient.OracleCommand.Execute(OciStatementHandle statementHandle, CommandBehavior behavior, Boolean needRowid, OciRowidDescriptor& rowidDescriptor, ArrayList& resultParameterOrdinals)
   at System.Data.OracleClient.OracleCommand.ExecuteNonQueryInternal(Boolean needRowid, OciRowidDescriptor& rowidDescriptor)
   at System.Data.OracleClient.OracleCommand.ExecuteNonQuery()
   at WFTools.Services.Persistence.Ado.AdoPersistenceResourceAccessor.InsertInstanceState(PendingWorkItem workItem, Guid ownerId, DateTime ownedUntil) in C:\Users\JK\Plus\WF\wftools-jul26\Main\Services\Persistence\Ado\AdoPersistenceResourceAccessor.cs:line 254
   at WFTools.Services.Persistence.GenericPersistenceService.Commit(Transaction transaction, ICollection items) in C:\Users\JK\Plus\WF\wftools-jul26\Main\Services\Persistence\GenericPersistenceService.cs:line 692