尝试阅读邮件时发现缺少或空的内容类型标头。内容类型标头是必需的

时间:2013-07-27 10:06:45

标签: web-services visual-studio-2012 odata sap

我正在使用SAP odata服务,我在Visual Studio 2012中将其添加为Web引用。

 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);

            }

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

"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(firefox附加组件)的响应

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

回复正文

<?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我收到以下回复:

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?

1 个答案:

答案 0 :(得分:0)

感谢Vitek Karas MSFT的建议。通过安装最新版本的WCF Data Services 5.6.0来解决该问题。并感谢Maikel尝试了我们的开发并且能够解决问题。