asp.net-web-apientity-framework-6odataasp.net-web-api2odatacontroller

OdataClient SaveChanges doesn't work and results an empty Microsoft.OData.Client.DataServiceResponse


I encapsulated the odata container because of some extensions:

public class Connector
{
    public string apiKey{get;set;}

    public  Connector(string apiKey)
    {
        this.apiKey = apiKey;
    }

    public Default.Container Get()
    {
        Default.Container container = new Default.Container(new Uri("http://documents.omnisoftonline.be/odata"));
        container.BuildingRequest += container_BuildingRequest;
        return container;
    }

    /// <summary>
    /// When fetching a single Document, you can enable this method to including fetch the binary data
    /// </summary>
    /// <param name="container"></param>
    /// <returns></returns>

    internal bool doIO = false;
    internal void container_BuildingRequest(object sender, BuildingRequestEventArgs e)
    {
        e.Headers.Add("X-ApiKey", apiKey);

        if (doIO && e.RequestUri.ToString().Contains("/Documents"))
        {
            e.RequestUri = new Uri(e.RequestUri.ToString() + (e.RequestUri.Query.Contains("?") ? "&" : "?") + "doIO=true");
        }


        this.container_BuildingRequest(sender, e);
    }
}

When i use my .dll ( using the Connector class), i have an empty result ( statuscode = -1, no headers, ...)The (normally) executed empty OdataServiceResponse

This is how i call the DLL

 documentsConnector.Get().AddToDocuments(docToCreate);
 var serviceResponse = documentsConnector.Get().SaveChanges(Microsoft.OData.Client.SaveChangesOptions.None); //tried several options
 foreach(var operationResponse in serviceResponse)
 {
      Console.WriteLine("Response: {0}", operationResponse.StatusCode); //no operationResponses, so this isn't executed
 }

It could be because my object isn't valid. But it's weird that i don't see any validation happening...

Any thoughts on how to propagate the SaveChanges() or pre-validate ( before submit) the Entity? The post isn't happening ( checked with Fiddler)


Solution

  • My wrapper class created a new container every time, so the entities got deleted from the Default.Container