2012-10-22 26 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。

相關問題