0
votes

After upgrading to WCF Data Services 5.0 for OData V3 i can't make insert or updates. The only thing that is possible are selects.

EDIT

Exception in overridden method HandleException:

Exception: System.Data.Services.DataServiceException: Content-Type header value missing. at System.Data.Services.HttpProcessUtility.ReadContentType(String contentType, String& mime, Encoding& encoding) at System.Data.Services.Serializers.Deserializer.CreateDeserializer(RequestDescription description, IDataService dataService, Boolean update, UpdateTracker tracker) at System.Data.Services.DataService1.HandlePostOperation(RequestDescription description, IDataService dataService) at System.Data.Services.DataService1.ProcessIncomingRequest(RequestDescription description, IDataService dataService) at System.Data.Services.DataService1.HandleNonBatchRequest(RequestDescription description) at System.Data.Services.DataService1.HandleRequest()

ResponseStatusCode: 400

Client-Code I set a token in the HTTP-Request-Header...

    /// <summary>
    /// Initializes a new instance of the <see cref="ServiceBase"/> class.
    /// </summary>
    /// <param name="uri">service uri</param>
    protected ServiceBase(Uri uri)
    {
        this.Context = new Entities(uri) { MergeOption = MergeOption.OverwriteChanges };
        this.Context.SendingRequest += new EventHandler<SendingRequestEventArgs>(this.ContextSendingRequest);
    }

    /// <summary>
    /// OnSendingRequest
    /// </summary>
    /// <param name="sender">source</param>
    /// <param name="e">event args</param>
    private void ContextSendingRequest(object sender, SendingRequestEventArgs e)
    {
        e.RequestHeaders["token"] = "xyassdfdfdfdf";
    }

Service-Code: The Service parses this Header and checks the token

    public XYDataService()
    {
        this.ProcessingPipeline.ProcessingRequest += this.ProcessingPipelineProcessingRequest;
    }


    /// <summary>
    /// OnProcessingRequest
    /// </summary>
    /// <param name="sender">source</param>
    /// <param name="e">event args</param>
    private void ProcessingPipelineProcessingRequest(object sender, DataServiceProcessingPipelineEventArgs e)
    {
        var authHeader = HttpContext.Current.Request.Headers["token"];

        if (string.IsNullOrEmpty(authHeader) || !authHeader.Equals("xyassdfdfdfdf"))
        {
            throw new DataServiceException(401, "401 Unauthorized");
        }
    }

Thanks for your help.

Andi

1
Can you please describe the scenario in a little bit more detail? What client are you using? If possible can you grab a trace using Fiddler?Vitek Karas MSFT
During SaveChanges i get the error. Selects are no problem. During Update or while adding new entries i get the error above. i am using the silverlight client. andiAndi Neuhauser
Can you please post the exception along with the callstack? Also please use Fiddler and grab a trace of the request/response which fails.Vitek Karas MSFT
var authHeader = HttpContext.Current.Request.Headers["token"]; this does not work when i comment this out it works. but i need to check a token set by the client?Andi Neuhauser
When you say "It doesn't work", could you please be more specific and post the exception you're getting with a callstack and ideally a small piece of the code you're dealing with?Vitek Karas MSFT

1 Answers

0
votes

Using answer since I need to put more text here.

I tried a very similar code to yours, but it works just fine:

DemoService ctx = new DemoService(new Uri("http://services.odata.org/(S(jcemln1vp0u1gqtoyqqpwrc1))/OData/OData.svc/"));
ctx.UsePostTunneling = true;
ctx.SendingRequest += (sender, ea) => { ea.RequestHeaders["token"] = "value"; };

ctx.UpdateObject(ctx.Products.First());
ctx.SaveChanges();

Running this using the latest WCF DS 5.0 bits from NuGet works. I also verified with Fiddler that it does send the Content-Type header.

Your request on the other hand doesn't have the Content-Type header. Can you please verify that you're using the latest NuGet packages and that the code you posted above is really what you're testing?