我已下载Olingo server sample(Odata4),已编译并部署在我的本地tomcat上
浏览网址http://localhost:8080/odata-server-sample/cars.svc/
我得到
<?xml version="1.0" encoding="UTF-8"?>
<app:service xmlns:app="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:metadata="http://docs.oasis-open.org/odata/ns/metadata" metadata:context="$metadata">
<app:workspace>
<atom:title>olingo.odata.sample.Container</atom:title>
<app:collection href="Cars" metadata:name="Cars">
<atom:title>Cars</atom:title>
</app:collection>
<app:collection href="Manufacturers" metadata:name="Manufacturers">
<atom:title>Manufacturers</atom:title>
</app:collection>
</app:workspace>
</app:service>
我不知道OData协议,但它似乎合法......
现在,如果我使用PowerQuery将其提供给Excel 2016: 数据&gt;新查询&gt;来自其他来源&gt;来自OData Feed
我收到错误Invalid URI: The hostname could not be parsed.
如果我使用这个vba代码:
Option Explicit
' References that need to be added:
' Microsoft XML, v6.0
' Microsoft Scripting Runtime
Const ODataErrorFirst As Long = 100
Const ODataCannotReadUrlError As Long = ODataErrorFirst + 1
Const ODataParseError As Long = ODataErrorFirst + 2
Sub test()
ODataReadUrl ("http://localhost:8080/odata-server-sample/cars.svc/")
End Sub
' Given a URL, reads an OData feed or entry into an XML document.
Function ODataReadUrl(ByVal strUrl As String) As MSXML2.DOMDocument60
Dim objXmlHttp As MSXML2.XMLHTTP60
Dim objResult As MSXML2.DOMDocument60
Dim strText As String
' Make a request for the URL.
Set objXmlHttp = New MSXML2.XMLHTTP60
objXmlHttp.Open "GET", strUrl, False
objXmlHttp.send
If objXmlHttp.Status <> 200 Then
Err.Raise ODataCannotReadUrlError, "ODataReadUrl", "Unable to get '" & strUrl & "' – status code: " & objXmlHttp.Status
End If
' Get the result as text.
strText = objXmlHttp.responseText
Set objXmlHttp = Nothing
' Create a document from the text.
Set objResult = New MSXML2.DOMDocument60
objResult.LoadXML strText
If objResult.parseError.ErrorCode <> 0 Then
Err.Raise ODataParseError, "ODataReadUrl", "Unable to load '" & strUrl & "' – " & objResult.parseError.reason
End If
Set ODataReadUrl = objResult
End Function
我得到Not valid at root level.
(在我的意大利语Excel中:Non valido al primo livello del documento.
)
这是什么意思? Olingo与excel不兼容?
答案 0 :(得分:4)
我已经遵循了一些建议,并提出了一个工作样本
您可以在此处找到修补后的代码:https://github.com/lelmarir/olingo-odata4/commit/8a947d3b7afab88c04177bfb361e9689ea91defc
参考文献:
答案 1 :(得分:0)
PowerQuery正在尝试读取OData Feed,但您提供的URL是服务文档的URL。
http://localhost:8080/odata-server-sample/cars.svc/
您需要将Feed的网址传递给它:
http://localhost:8080/odata-server-sample/cars.svc/Cars
或
http://localhost:8080/odata-server-sample/cars.svc/Manufacturers
Feed是一个条目列表 - 它是实际数据。服务文档列出了不同的可用供稿,以便客户可以发现它们。