我正在按照本教程尝试使用odata服务
我已按照教程的说明下载并安装了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.
我可以通过浏览器浏览它。
有什么问题?
答案 0 :(得分:0)
我不确定教程中是否有错误,我尝试使用Uri进行试验,但添加http://localhost:52868/odata
作为参考作品,http://localhost:52868/odata/Products
并非如此