尝试使用odata web api服务时出错

时间:2013-02-19 06:19:38

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

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

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

有什么问题?

1 个答案:

答案 0 :(得分:0)

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

相关问题