When i try to send an instance of MULTIMEDIA type, with
hasStream="true"
property set to true, the WCF Data Server seems not to receive entity data.
On the client side i iterate over a collection of objects and i try to send them to another wcf data service. The reference to the "other wcf data service" is:
this.centralCtx
Also i set the saved stream for the each new entity and initialize all properties copying them from the source entity:
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);
}
This is change interceptor code:
[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;
}
}
All the properties of changedObject on the server inside MULTIMEDIA change interceptor are always null. Why?
I finally got the answer. The sending of an entity marked with the attribute hasStream implies two requests.
That's why during the first request to the server all the properties of the object are null.