Windows Workflow 4 Correlation Query includes website instance name in instance key calculation and fails

后端 未结 5 1818
梦谈多话
梦谈多话 2021-01-26 23:22

I am trying to host a long running workflow service on Azure but I am having problems with correlation.
I have got the timeToUnload and the timeToPersist set to 0 and I have

5条回答
  •  旧时难觅i
    2021-01-26 23:42

    After decompiling and searching a lot, I finnaly found where the key is Generated.

    In the class System.ServiceModel.Channels.CorrelationKey, System.ServiceModel

    The method GenerateKeyString does the trick. Now I have to find a way to override this method and make my own generating key algorithm so the same instance can run in multiple web servers with different names.

    private static Guid GenerateKey(string keyString)
    {
      return new Guid(HashHelper.ComputeHash(Encoding.Unicode.GetBytes(keyString)));
    }
    
    private static string GenerateKeyString(ReadOnlyDictionaryInternal keyData, string scopeName, string provider)
    {
      if (string.IsNullOrEmpty(scopeName))
        throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("scopeName", System.ServiceModel.SR.GetString("ScopeNameMustBeSpecified"));
      if (provider.Length == 0)
        throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("provider", System.ServiceModel.SR.GetString("ProviderCannotBeEmptyString"));
      StringBuilder stringBuilder1 = new StringBuilder();
      StringBuilder stringBuilder2 = new StringBuilder();
      SortedList sortedList = new SortedList((IDictionary) keyData, (IComparer) StringComparer.Ordinal);
      stringBuilder2.Append(sortedList.Count.ToString((IFormatProvider) NumberFormatInfo.InvariantInfo));
      stringBuilder2.Append('.');
      for (int index = 0; index < sortedList.Count; ++index)
      {
        if (index > 0)
          stringBuilder1.Append('&');
        stringBuilder1.Append(sortedList.Keys[index]);
        stringBuilder1.Append('=');
        stringBuilder1.Append(sortedList.Values[index]);
        stringBuilder2.Append(sortedList.Keys[index].Length.ToString((IFormatProvider) NumberFormatInfo.InvariantInfo));
        stringBuilder2.Append('.');
        stringBuilder2.Append(sortedList.Values[index].Length.ToString((IFormatProvider) NumberFormatInfo.InvariantInfo));
        stringBuilder2.Append('.');
      }
      if (sortedList.Count > 0)
        stringBuilder1.Append(',');
      stringBuilder1.Append(scopeName);
      stringBuilder1.Append(',');
      stringBuilder1.Append(provider);
      stringBuilder2.Append(scopeName.Length.ToString((IFormatProvider) NumberFormatInfo.InvariantInfo));
      stringBuilder2.Append('.');
      stringBuilder2.Append(provider.Length.ToString((IFormatProvider) NumberFormatInfo.InvariantInfo));
      stringBuilder1.Append('|');
      stringBuilder1.Append((object) stringBuilder2);
      return ((object) stringBuilder1).ToString();
    }
    

提交回复
热议问题