luobo2ni 发表于 2015-9-26 12:44:26

SharePoint工作流开发点滴(4)

  最近在开发SharePoint工作流总是发生一个错误 :工作流开始之后便显示"已完成"或者开始之后报错"内部错误".
  查看当时的日志,发现下面的段落:

  02/06/2007 10:31:03.92         w3wp.exe (0x0758)         
  0x0F3C      Windows SharePoint Services         Workflow Infrastructure         72eo      Unexpected         
  DehydrateInstance: System.Runtime.Serialization.SerializationException: 在分析完成之前就遇到流结尾。
  在 System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
  在 System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
  在 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
  在 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
  在 System.Workflow.ComponentModel.Activity.Load(Stream stream, Activity outerActivity, IFormatter formatter)...         
  
  
  02/06/2007 10:31:03.92*      w3wp.exe (0x0758)         
  0x0F3C      Windows SharePoint Services         Workflow Infrastructure         72eo      Unexpected      ...
  在 System.Workflow.ComponentModel.Activity.Load(Stream stream, Activity outerActivity)
  在 System.Workflow.Runtime.Hosting.WorkflowPersistenceService.RestoreFromDefaultSerializedForm(Byte[] activityBytes, Activity outerActivity)
  在 Microsoft.SharePoint.Workflow.SPWinOePersistenceService.LoadWorkflowInstanceState(Guid instanceId)
  在 System.Workflow.Runtime.WorkflowRuntime.InitializeExecutor(Guid instanceId, CreationContext context, WorkflowExecutor executor, WorkflowInstance workflowInstance)
  在 System.Workflow.Runtime.WorkflowRuntime.Load(Guid key, CreationContext context, WorkflowInstance workflowInstance) 在 System.Workflow.Runtime.WorkflowRuntime.GetWorkflow(Guid instanceId)
  在 Microsoft.SharePoint.Workflow.SPWinOeHostServices.DehydrateInstance(SPWorkflowInstance wo...         
  
  02/06/2007 10:31:03.92*      w3wp.exe (0x0758)         
  0x0F3C      Windows SharePoint Services         Workflow Infrastructure         72eo      Unexpected      ...rkflow)
  
  
  02/06/2007 10:31:03.93         w3wp.exe (0x0758)         
  0x0F3C      Windows SharePoint Services         Workflow Infrastructure         88xr      Unexpected      WinWF Internal Error, terminating workflow Id# 472dae03-5465-4f04-876f-d4cc4caa902a
  看里边最长的一段中文描述:"在分析完成之前就遇到流结尾",如果是SharePoint英文版,这段错误信息应该是"End of Stream encountered before parsing was completed".
  也就是说Workflow Runtime根本就没有完整的分析完整个流程.
  再看这句中文之前的英文:"DehydrateInstance: System.Runtime.Serialization.SerializationException".
  原来工作流是在钝化实例的时候发生了序列化异常.
  回想一下工作流的持久性,Workflow Runtime会把空闲的工作流数据序列化为XML形式,然后把工作流实例从内存中清除,等到需要的时候再将其反序列化加载到内存.
  会不会是因为我在工作流项目中添加了自定义类,而这个类又不支持序列化,所以导致工作流序列化失败?
  在工作流中使用InfoPath Initiation(或者Association)表单时需要为其生成一个类,观察这个类,发现这个用XSD生成的类有如下特性来修饰:

  
  
  
  
  
  
  下面来逐行分析一下:
  
  表示这个类是由XSD工具生成的.
  
  表示这个类可以被序列化,我想关键就在这里.
  
  表示调试器会自动忽略被修饰的类内部的断点
  
  表示设计器的类别是"code"
  
  表示系列化时生成的XSD架构是匿名类型
  
  设置序列化时根元素的命名空间
  删去或修改我们不需要的特性(比如第一项),将其插入到我们的自定义类中,工作流就正常了.
  
  update 2008.12.25

[*]其实只需要将自定义类标识为即可。
[*]其实不仅是自定义类,只要是在工作流类中的类级别变量,都必须实现了ISerializable的,而方法内的局部变量则可以不支持序列化。否则工作流在进行钝化是无法序列化某些变量,也会导致这个错误。比如在工作流累中定义了一个XmlDocument,就会发生此错误。
页: [1]
查看完整版本: SharePoint工作流开发点滴(4)