执行Microsoft.OData.Client服务时出错404?

时间:2015-03-26 06:56:24

标签: c# asp.net-mvc c#-4.0 odata

我在执行Microsoft.OData.Client Service

时遇到以下错误

它只是提供异常IIS 8.0 Detailed Error - 404.0 - Not Found

但是当我使用浏览器尝试使用相同的服务时,它完全正常运行

我试图在执行 -

之后调用服务,例如跟随获取异常
MyDataServiceClient myDataServiceClient = new MyDataServiceClient(new Uri("http://localhost:64555/mydev"));
                var query = myDataServiceClient.AllLanguage;
                List<Language> languageList = query.ToList();

这里有什么问题? 在WebApiConfig.cs

private static IEdmModel model = null;
  private static IEdmModel model = null;

        public MyDataServiceClient(Uri serviceRoot)
            : base(serviceRoot, DataServiceProtocolVersion.V3)
        {
            this.Format.LoadServiceModel = this.LoadServiceModel;
            this.Format.UseJson();
        }

        private Microsoft.Data.Edm.IEdmModel LoadServiceModel()
        {
            try
            {

                if (model == null)
                {
                    var metadataUri = this.GetMetadataUri();
                    var request = WebRequest.CreateHttp(metadataUri);

                    using (var response = request.GetResponse())
                    using (var stream = response.GetResponseStream())
                    using (var reader = System.Xml.XmlReader.Create(stream))
                    {
                        model = Microsoft.Data.Edm.Csdl.EdmxReader.Parse(reader);
                    }
                }
                return model;
            }
            catch (Exception exception)
            {

                return null;
            }
        }

给出错误:

  

解析EDMX文档时遇到以下错误:   UnexpectedXmlElement:根元素的元素'edmx:Edmx'是意外的。根元素应该是Edmx。 :(2,2)

详情异常

System.Data.Services.Client.DataServiceQueryException was unhandled
  HResult=-2146233079
  Message=An error occurred while processing this request.
  Source=Microsoft.Data.Services.Client
  StackTrace:
       at System.Data.Services.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)
       at System.Data.Services.Client.DataServiceQuery`1.Execute()
       at System.Data.Services.Client.DataServiceQuery`1.GetEnumerator()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
  InnerException: System.Data.Services.Client.DataServiceClientException
       HResult=-2146233079
       Message=<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>IIS 8.0 Detailed Error - 404.0 - Not Found</title> 

0 个答案:

没有答案