A missing or empty content type header was found when trying to read a message. The content type header is required

Imir Hoxha

I am using a SAP odata service and I added it as a web reference in visual studio 2012.

 Uri serviceUri = new Uri("http://zbc.net:4521/sap/opu/odata/sap/Emp/", UriKind.Absolute);
            Emp context = new Emp(serviceUri);

            context.Credentials = new System.Net.NetworkCredential("loginanme", "pass");

            var query = from b in context.Employees
                        where b.Role == "Admin"
                        select b;

            foreach (var myObject in query)
            {
                Console.WriteLine("\n name: {0} | role: {1}", myObject.name, myObject.Role);

            }

When I execute the code above, I get the following error:

"An error occurred while processing this request."

InnerException: "A missing or empty content type header was found when trying to read a message. The content type header is required."

this is the query that VS2012 produces:

Query: {http://zbc.net:4521/sap/opu/odata/sap/Emp/Employees()?$filter=Role eq 'Admin'}

StackTrace:

   at Microsoft.Data.OData.ODataMessageReader.GetContentTypeHeader()
   at Microsoft.Data.OData.ODataMessageReader.TryGetSinglePayloadKindResultFromContentType(IEnumerable`1& payloadKindResults, MediaType& contentType, Encoding& contentEncoding)
   at Microsoft.Data.OData.ODataMessageReader.DetectPayloadKind()
   at System.Data.Services.Client.Materialization.ODataMaterializer.CreateODataMessageReader(IODataResponseMessage responseMessage, ResponseInfo responseInfo, Boolean projectionQuery, ODataPayloadKind& payloadKind)
   at System.Data.Services.Client.Materialization.ODataMaterializer.CreateMaterializerForMessage(IODataResponseMessage responseMessage, ResponseInfo responseInfo, Type materializerType, QueryComponents queryComponents, ProjectionPlan plan, ODataPayloadKind payloadKind)
   at System.Data.Services.Client.MaterializeAtom..ctor(ResponseInfo responseInfo, QueryComponents queryComponents, ProjectionPlan plan, IODataResponseMessage responseMessage, ODataPayloadKind payloadKind)
   at System.Data.Services.Client.QueryResult.CreateMaterializer(ProjectionPlan plan, ODataPayloadKind payloadKind)
   at System.Data.Services.Client.QueryResult.ProcessResult[TElement](ProjectionPlan plan)
   at System.Data.Services.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)

Response from RESTClient (firefox add-on)

Status Code: 200 OK
Content-Encoding: gzip
Content-Length: 566
Content-Type: application/xml
Last-Modified: Tue, 09 Jul 2013 13:03:22 GMT
Server: SAP NetWeaver Application Server / ABAP 731
dataserviceversion: 2.0

Response body

<?xml version="1.0" encoding="utf-8"?>
    <edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" 
    xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" 
    xmlns:sap="http://www.sap.com/Protocols/SAPData">
    <edmx:DataServices m:DataServiceVersion="2.0">
    <Schema Namespace="Emp" xml:lang="en" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
    <EntityType Name="Bank" sap:content-version="1">
    <Key>
        <PropertyRef Name="Admin"/>
    </Key>
     <Property Name="Name" Type="Edm.String" MaxLength="35" sap:label="Name"/>
    <Property Name="street" Type="Edm.String" MaxLength="35" sap:label="Street"/>
    <Property Name="Role" Type="Edm.String" MaxLength="35" sap:label="Role"/>
    <Property Name="Region" Type="Edm.String" MaxLength="3" sap:label="Region"/>
    </EntityType>
    <EntityContainer Name="Emp" m:IsDefaultEntityContainer="true">
    <EntitySet Name="Employees" EntityType="Emp.Employee" sap:deletable="false" sap:content-version="1"/>
    </EntityContainer>
    <atom:link rel="self" href="http://zbc.net:4521/sap/opu/odata/sap/Emp/$metadata" xmlns:atom="http://www.w3.org/2005/Atom"/>
    <atom:link rel="latest-version" href="http://zbc.net:4521/sap/opu/odata/sap/Emp/$metadata" 
    xmlns:atom="http://www.w3.org/2005/Atom"/>
    </Schema>
    </edmx:DataServices>
    </edmx:Edmx>

From Fiddler I get the following response:

HTTP/1.1 401 Unauthorized
www-authenticate: Basic realm="SAP NetWeaver Application Server [SVD/800]"
content-length: 2180
content-type: text/html; charset=utf-8
server: SAP NetWeaver Application Server / ABAP 731

How come in fiddler I get a 401? How can I provide a login and pass in Fiddler so that I don't get a 401?

Imir Hoxha

Thanks Vitek Karas MSFT for your suggestion. The issue is sovled by installing the latest version of WCF Data Services 5.6.0. and thanks to Maikel who tried in on our dev and was able to solve the issue.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Set default content type header of Spring RestTemplate

HTTP Content-Type Header and JSON

What 'Content-Type' header to use when serving gzipped files?

What content type should be in http header of soap 1.2 message?

FormData boundary missing from content-type in POST request header

Can't set Content-Type header

Should Content-Type header be present when the message body is empty?

How to set Content-Type header for JMS message

Matching charset of HTTP Header Content-Type

When to use header('Content-Type: application/json') in PHP

Content-type header not supported

How to set the content-type header to nothing?

RabbitMQ Ignore Header Content-Type

Content type header is not supported error message

How to check if website is missing header that prevents content type sniffing

What is the purpose of Content-Type at response header?

Remove charset in Content-Type header

Content Type Header in Azure Function

Multipart Content-Type header is updated by Karate when sending requests

Get PHP content-type from header()

jQuery: Content type header is not set

Set Content-Type header

content-type header missing in angular service call

python curl unable to PUT empty content type in header

axios not overriding default content-type header to

What's the use of Content-Type header when the response is an attachment?

Trying to get Spring Boot app to send an error response message when request does not have "Content-type" HTTP request header

What is the header Content type suppose to do?

Testing Content-Type in Response Header