【问题标题】:Error when trying to consume odata webapi service尝试使用 odata webapi 服务时出错
【发布时间】:2013-02-03 18:08:46
【问题描述】:

我正在按照本教程尝试使用 odata 服务

http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/getting-started-with-odata-in-web-api/create-an-odata-client

我已按照教程的说明下载并安装了 WCF 数据服务工具 5.2。

但是,当我尝试添加服务引用时,出现以下错误:

The document at the url http://localhost:52868/odata/Products was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'XML Schema' is 'Data at the root level is invalid. Line 1, position 1.'.
- Report from 'DISCO Document' is 'Data at the root level is invalid. Line 1, position 1.'.
- Report from 'WSDL Document' is 'There is an error in XML document (1, 1).'.
  - Data at the root level is invalid. Line 1, position 1.
Metadata contains a reference that cannot be resolved: 'http://localhost:52868/odata/Products'.
The content type application/json; odata=minimalmetadata; streaming=true; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '{
  "odata.error":{
    "code":"","message":{
      "lang":"en-US","value":"An error has occurred."
    },"innererror":{
      "message":"No MediaTypeFormatter is available to read an object of type 'Product' from content with media type 'application/soap+xml'.","type":"System.InvalidOperationException","stacktrace":"   at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)\r\n   at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)\r\n   at System.Web.Http.ModelBinding.FormatterParameterBinding.ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)\r\n   at System.Web.Http.OData.PerRequestParameterBinding.ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancel'.
The remote server returned an error: (500) Internal Server Error.
If the service is defined in the current solution, try building the solution and adding the service reference again.

我可以通过浏览器浏览它。

怎么了?

【问题讨论】:

    标签: asp.net web-services asp.net-web-api odata webservice-client


    【解决方案1】:

    我不确定这是否是教程中的错误,我尝试使用 Uri 进行试验,但添加 http://localhost:52868/odata 作为参考作品,http://localhost:52868/odata/Products 没有

    【讨论】:

    • localhost:52868/odata 是服务的根。您应该将“添加服务引用”对话框指向您的 odata 服务的根目录。
    猜你喜欢
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    • 1970-01-01
    • 2014-05-04
    相关资源
    最近更新 更多