首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在试图读取消息时,会发现缺少或空的内容类型标头。需要内容类型标头。

在试图读取消息时,会发现缺少或空的内容类型标头。需要内容类型标头。
EN

Stack Overflow用户
提问于 2013-07-27 10:06:44
回答 1查看 3.9K关注 0票数 1

我正在使用SAP odata服务,我在visual 2012中添加了它作为web参考。

代码语言:javascript
运行
复制
 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);

            }

当我执行上面的代码时,我会得到以下错误:

代码语言:javascript
运行
复制
"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)

来自 RESTClient (火狐插件)的响应

代码语言:javascript
运行
复制
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

反应体

代码语言:javascript
运行
复制
<?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>

来自Fiddler的我得到了以下响应:

代码语言:javascript
运行
复制
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

为什么我能拿到401?我如何提供一个登录和传入Fiddler,这样我就不会得到401?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-11 12:29:24

感谢维特克卡拉斯MSFT的建议。安装最新版本的WCF数据服务5.6.0解决了这个问题。感谢梅克尔,他尝试了我们的开发,并能够解决这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17896554

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档