如何调试通过 UpdateListItems SOAP API 在 SharePoint 中创建列表项时出现的错误?
我在调试 SharePoint SOAP 调用以创建列表项时遇到了非常困难的情况。我发送的 SOAP 正文是:
<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns0:Body>
<ns1:UpdateListItems>
<ns1:listName>{35BC2CB3-D2FB-4D47-B711-7502819D6E2B}</ns1:listName>
<ns1:updates>
<Batch OnError="Continue" ListVersion="1">
<Method ID="1" Cmd="New">
<Field Name="ID">New</Field>
<Field Name="Title">Test Summary</Field>
</Method>
</Batch>
</ns1:updates>
</ns1:UpdateListItems>
</ns0:Body>
</SOAP-ENV:Envelope>
无论我做什么,我总是会返回一个 SoapServerException,其详细信息为“值未落在预期范围内”。这是在我拥有完全访问权限的 SharePoint 网站上。这是一个新创建的列表,标题是唯一必需的属性。我如何找出问题所在?
FWIW,我对 GetList 和 GetListItems 等其他方法没有问题。我只是没有运气使用 UpdateListItems 添加新的列表项。
I'm having a really tough time debugging a SharePoint SOAP call to create a list item. The SOAP body I'm sending is:
<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns0:Body>
<ns1:UpdateListItems>
<ns1:listName>{35BC2CB3-D2FB-4D47-B711-7502819D6E2B}</ns1:listName>
<ns1:updates>
<Batch OnError="Continue" ListVersion="1">
<Method ID="1" Cmd="New">
<Field Name="ID">New</Field>
<Field Name="Title">Test Summary</Field>
</Method>
</Batch>
</ns1:updates>
</ns1:UpdateListItems>
</ns0:Body>
</SOAP-ENV:Envelope>
No matter what I do, I always get back a SoapServerException with, "Value does not fall within the expected range," as the detail. This is on a SharePoint site that I have full access to. It's a newly created list with Title as the only required attribute. How do I figure out what the issue is?
FWIW, I have no problem with other methods like GetList and GetListItems. I'm just having no luck using UpdateListItems to add a new list item.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
TLDR:在尝试第一次更新调用之前尝试设置
client.options.prettyxml = True
。天哪,我一整天都在与一个明显相同的问题搏斗。假设您使用类似的 suds 版本(此处为 suds_jurko 0.5),那么“我如何更好地调试它?”的答案在某种程度上,正在记录:
在 sax 文档/元素(或与其相邻)的某处存在一个错误,导致“element.plain()”函数认为该元素为空。当 client.options.prettyxml 为 False 时,SoapClient.send() 尝试使用 sax Document 的 'plain()' 方法而不是 str() 方法。其结果是该元素被解析为空,导致 UpdateListItems 失败并出现“值不在预期范围内”错误。
例如:
请注意,GetListItems() 方法也对我“有效”,因为 sax 在该 SOAP 调用中放置了一个空查询元素,这在技术上是没问题的。
要解决此问题,请在调用第一个服务之前在某处添加
client.options.prettyxml = True
来强制 SoapClient.send() 使用“pretty”版本。我没有注意到这个错误,因为我显然是在 SOAP 对象被损坏之前检查它;打开日志记录会显示最后一刻的更改。
(我意识到这是一个老问题,不确定这是否会让人皱眉;但这是我之前能够找到的最接近我的实际问题的问题,并认为它值得一个答案)
TLDR: Try setting
client.options.prettyxml = True
before you try your first update call.Holy hell, I've been wrestling with an apparently identical issue for a whole day. Assuming you were using a similar suds version (suds_jurko 0.5 here), the answer to "how do I better debug this?" to a degree, was logging:
There is a bug nestled somewhere in the sax document/elements (or adjacent to them) that was causing the "element.plain()" function to think the element was empty. When client.options.prettyxml is False, SoapClient.send() tries to use the 'plain()' method of the sax Document instead of the str() method. The result of this was that the element was getting parsed as empty, causing the UpdateListItems to fail with the "Value does not fall within the expected range," error.
ex:
Note that the GetListItems() methods 'worked' for me as well, because the sax was putting an empty query element in that SOAP call, which was technically fine.
To workaround this, force SoapClient.send() to use the 'pretty' version by adding
client.options.prettyxml = True
somewhere before you invoke your first service.I had not noticed the fault, because I was apparently checking my SOAP object before it got mangled; turning on the logging revealed the last minute alteration.
(I realize this is an old question, not sure if that's frowned upon; but it was the closest I was able to find to my actual problem earlier and felt it deserved an answer)
我自己也有这个问题。
这是我使用的代码,它似乎有效:
I had this issue myself.
This is the code I used and it seems to work:
请确保您的列表 ID 正确,并且字段仅使用您要添加项目的列表的内部名称。
尝试将您的方法放入 try catch 块中。将以下部分放在 catch 块上方以获取异常的更多详细信息。
Please ensure your list ID is correct and fields are using internal names only for the list you are adding item.
Try putting your method inside try catch block. Put below section above catch block to have further details for the exception.