简体   繁体   中英

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, ...) (通常)执行的空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)

我的包装器类每次都创建一个新容器,因此实体从Default.Container中删除。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM