2012-10-22 27 views
0

当我尝试发送多媒体类型的实例,与WCF数据客户端不发送实体属性值

hasStream="true" 

属性设置为true,WCF数据服务器似乎不接收实体数据。

在客户端我迭代对象的集合,我尝试将它们发送到另一个wcf数据服务。到“另一WCF数据服务”的基准是:

this.centralCtx 

此外,我设置保存流用于每一个新的实体,并且初始化所有属性从源实体将它们复制:

foreach (LOCAL_TYPE localObject in localObjects) 
{ 
    if (entityName == "MULTIMEDIA") 
     { 
      CentralService.ARTICOLI article = null; 
      CentralService.MULTIMEDIA multimedia = new CentralService.MULTIMEDIA(); 
      LocalService.MULTIMEDIA lMultimedia = localObject as LocalService.MULTIMEDIA; 
      multimedia.ID_MULTIMEDIA = lMultimedia.ID_MULTIMEDIA; 
      multimedia.DATA_CREAZIONE = lMultimedia.DATA_CREAZIONE; 
      multimedia.DATA_ULTIMA_MODIFICA = lMultimedia.DATA_ULTIMA_MODIFICA; 
      multimedia.ARTICOLO_ID = lMultimedia.ARTICOLO_ID; 

      this.centralCtx.TryGetEntity(
      new Uri(this.centralCtx.BaseUri + "ARTICOLI('" + multimedia.ARTICOLO_ID 
      + "')", UriKind.Absolute), out article); 

      article.MULTIMEDIA.Add(multimedia); 
      this.centralCtx.AddRelatedObject(article, "MULTIMEDIA", multimedia); 
      DataServiceStreamResponse streamResponse = this.localCtx.GetReadStream(localObject); 
      this.centralCtx.SetSaveStream(multimedia, streamResponse.Stream, 
         true, "image/jpeg", ""); 
      //this.centralCtx.UpdateObject(article); 
     } 
     else { 
      CENTRAL_TYPE cloned = DbHelper.FlatCloneFromType<LOCAL_TYPE, CENTRAL_TYPE> 
            (localObject, centralCtx); 
      this.centralCtx.AddObject(entityName, cloned); 
     } 
     } 

     try 
     { 
     this.centralCtx.SaveChanges(); 
     Notify(progressAction, "Exported table " + entityName, null); 
     successAction(this.Log); 
     } 
     catch (Exception ex) 
     { 
     Notify(progressAction, "Error exporting table " + entityName, ex); 
     this.synchResult = SynchResultType.Error; 
     exceptionAction(ex); 
     } 

这是更改拦截器代码:

[ChangeInterceptor("MULTIMEDIA")] 
    public void OnChangeMultimedia(MULTIMEDIA changedObject, UpdateOperations op) 
    { 
     switch (op) 
     { 
      case UpdateOperations.Add: 
       if(changedObject.ID_MULTIMEDIA == null) 
        changedObject.ID_MULTIMEDIA = Guid.NewGuid().ToString(); 
       changedObject.STATO_INTERNO = "TRASFERITO"; 
       changedObject.DATA_ULTIMA_MODIFICA = changedObject.DATA_ULTIMA_MODIFICA == null 
        ? DateTime.Now.ToLocalTime() : changedObject.DATA_ULTIMA_MODIFICA; 
       this.CurrentDataSource.SaveChanges(); 
       break; 
      default: break; 
     } 
    } 

MULTIMEDIA更改拦截器内服务器上changedObject的所有属性始终为空。为什么?

回答

1

我终于得到了答案。 发送标记有属性hasStream的实体意味着两个请求。

  1. 第一种是POST,在此期间服务器在数据库中创建记录并将文件保存在文件系统上。
  2. 第二个是在其期间客户机执行更新从服务器

这就是为什么在第一请求到服务器时的对象的所有属性都为空传递ID的MERGE。

相关问题