我有一个OData服务,该服务从/$metadata
端点返回以下内容:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0">
<Schema Namespace="(...)" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<!-- ... -->
</Schema>
</edmx:DataServices>
</edmx:Edmx>
当我尝试对此XML文件运行OData v4客户端代码生成器(v2.3.0)时,出现以下错误:
警告:正在运行转换:元素'edmx:Edmx'对于根元素而言是意外的。根元素应该是Edmx。
警告:未声明' http://schemas.microsoft.com/ado/2007/08/dataservices/metadata:DataServiceVersion '属性。
我也只看到一个空的.cs
输出文件。
我尝试过从和元素中删除edmx:
名称空间前缀,将该名称空间设置为默认名称,并在其余元素上调整前缀,但这都不起作用:<Edmx>
<DataServices>
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Edmx Version="1.0" xmlns="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:edm="http://schemas.microsoft.com/ado/2008/09/edm">
<DataServices m:DataServiceVersion="1.0">
<edm:Schema Namespace="(...)">
<!-- ... -->
</edm:Schema>
</DataServices>
</Edmx>
好的,看来问题可能出在该服务正在公开的OData版本上,即OData v1.0。edm
定义的名称空间为http://schemas.microsoft.com/ado/2006/04/edm
。请参见OData版本4.0第3部分:通用模式定义语言(CSDL),第2.2节:
定义OData Service公开的实体模型的元素和属性使用Entity Data Model命名空间进行限定:
CSDL的早期版本对EDM使用以下名称空间:
- CSDL版本1.0:http://schemas.microsoft.com/ado/2006/04/edm
- CSDL版本1.1:http://schemas.microsoft.com/ado/2007/05/edm
- CSDL版本1.2:http://schemas.microsoft.com/ado/2008/01/edm
- CSDL 2.0版:http://schemas.microsoft.com/ado/2008/09/edm
- CSDL 3.0版:http://schemas.microsoft.com/ado/2009/11/edm
使用Visual Studio 2013中的“添加服务参考”工具(可选地安装了此更新)解决了为该OData服务生成客户端代码的问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句