1

我正在按照本教程尝试使用 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.

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

怎么了?

4

1 回答 1

0

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

于 2013-02-19T10:54:05.407 回答