内部例外1: DataServiceQueryException:处理此请求时发生错误。
内部例外2: InvalidOperationException:响应有效内容不是有效的响应有效内容。请确保顶级元素是有效的Atom或JSON元素或属于“http://docs.oasis-open.org/odata/ns/data”命名空间。
我收到一个非常奇怪的错误,当我编译应用程序时,一旦odata客户端进入数据库就会编译它然后崩溃并出现上述错误。我已经对此做了一些研究,我可以看到它基本上是从odata请求中寻找元数据。但是,我提供了它,当我在邮差中运行uri时,它可以工作。所以我的问题是我做错了什么?
C#:
public const string MetadataDocumentUri = "http://localhost/QuickQuoteApi/odata/$metadata";
我到达控制器并执行正常。非常感谢帮助
我正在使用Devexpres GridControl
来访问数据源。
<dx:WcfCollectionViewSource x:Key="WcfCollectionViewSource"
Culture="en-US"
ContextType="{x:Type QuickQuote:QuickQuoteContainer}"
CollectionViewType="{x:Type ListCollectionView}"
Path="Companies"
ServiceRoot="http://localhost/QuickQuoteApi/odata/">
<dx:DesignDataManager.DesignData>
<dx:DesignDataSettings RowCount="5"/>
</dx:DesignDataManager.DesignData>
</dx:WcfCollectionViewSource>
</dx:DXWindow.Resources>
<Grid>
<dxg:GridControl AutoGenerateColumns="AddNew" EnableSmartColumnsGeneration="True" ItemsSource="{Binding Data, Source={StaticResource WcfCollectionViewSource}}">
<dxg:GridControl.View>
<dxg:TableView AllowPerPixelScrolling="True" ShowTotalSummary="True" IsSynchronizedWithCurrentItem="True"/>
</dxg:GridControl.View>
</dxg:GridControl>
我还添加了webapi配置
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Microsoft.OData.Edm.IEdmModel edmModel = GetEdmModel();
config.MapODataServiceRoute("OdataRoute", "odata", edmModel);
config.Formatters.Add(new JsonMediaTypeFormatter());
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling =
Newtonsoft.Json.ReferenceLoopHandling.Ignore;
config.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.None;
}
private static Microsoft.OData.Edm.IEdmModel GetEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.Namespace = "QuickQuote";
builder.ContainerName = "QuickQuoteContainer";
builder.EntitySet<Address>("Addresses");
builder.EntitySet<Company>("Companies");
builder.EntitySet<Connector>("Connectors");
builder.EntitySet<Contact>("Contacts");
builder.EntitySet<ContactType>("ContactTypes");
builder.EntitySet<Coordinate>("Coordinates");
builder.EntitySet<FromTo>("FromTos");
builder.EntitySet<Manufacturer>("Manufacturer");
builder.EntitySet<Nc>("Ncs");
builder.EntitySet<Position>("Positions");
builder.EntitySet<Product>("Products");
builder.EntitySet<Question>("Questtions");
builder.EntitySet<Quote>("Quotes");
builder.EntitySet<Role>("Roles");
builder.EntitySet<SingleTerminal>("SingleTerminals");
builder.EntitySet<TotalHeader>("TotalHeaders");
builder.EntitySet<TotalItem>("TotalItems");
builder.EntitySet<TotalLabel>("TotalLabels");
builder.EntitySet<User>("Users");
builder.EntitySet<Worksheet>("Worksheets");
builder.EntitySet<WorksheetLabel>("WorksheetLabels");
return builder.GetEdmModel();
}
}