1

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.

Cees Timmerman
  • 17,623
  • 11
  • 91
  • 124
King Chung Huang
  • 5,026
  • 28
  • 24
  • How are you generating this SOAP envelope? The only thing I wonder about is that you've explicitly declared your namespace (`ns1`) for `UpdateListItems`, `listName` and `updates`. If you're doing this, wouldn't you need to declare it on the child nodes of `updates` as well? – CBono May 04 '11 at 21:20
  • I'm using the suds module in Python to generate the SOAP envelope and do all the grunt work. I did try specifying the namespace on the child nodes of `updates` as well, with the same result. – King Chung Huang May 05 '11 at 15:03
  • And you're accessing the List web service under the same site to which your list belongs? For instance, you shouldn't access the service from the root `http:///_vti_bin/lists.asmx` if your list actually lives in a subsite. – CBono May 05 '11 at 15:17
  • Yes, it's not in a subsite. And, I'm able to call GetList and GetListItems successfully. – King Chung Huang May 05 '11 at 15:33

3 Answers3

3

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:

import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)

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:

MESSAGE:
b'<?xml version="1.0" encoding="UTF-8"?>
<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>B5E50422-D16B-4C5F-AE19-CFBE943C6F3F</ns1:listName>
  <updates/>
</ns1:UpdateListItems>
</ns0:Body>
</SOAP-ENV:Envelope>'

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)

Argle
  • 68
  • 5
  • Wow, I'd totally forgotten about this question! But, you're absolutely correct. I did eventually figure out that setting client.options.prettyxml = True was the key, and for the exact reasons you stated. Sorry you had to go through that, too! – King Chung Huang Jan 29 '14 at 02:33
  • Thank you! I've wasted days on this. According to [this ticket](https://fedorahosted.org/suds/ticket/463), the unreleased version after 0.4 should have patched this issue. – Cees Timmerman Mar 24 '14 at 14:21
  • I just spent all day figuring this out as well. – Tmdean Aug 05 '14 at 21:13
1

I had this issue myself.

This is the code I used and it seems to work:

batch = Element('Batch').append(Attribute('OnError', 'Return'))
batch.append(Attribute('ListVersion', '1'))

method = Element('Method').append(Attribute('ID', '1'))
method.append(Attribute('Cmd', 'Update'))

method.append(Element('Field').append(Attribute('Name', 'ID')).setText(1))
method.append(Element('Field').append(Attribute('Name', 'Title')).setText('Just Changed It23223'))

batch.append(method)

updates = Element('ns1:updates')
updates.append(batch)

client.service.UpdateListItems('Test', updates)
Tisho
  • 8,320
  • 6
  • 44
  • 52
Jason
  • 11
  • 2
0

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.

catch (soapserver.soapserverexception ex)
{    
     console.writeline(ex.detail.innertext);
}
ashish.chotalia
  • 3,696
  • 27
  • 28
  • Based on the [Lists.UpdateListItems Method](http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems.aspx) documentation, I've been putting New as the ID for new list items. I've also tried omitting the ID field altogether, with no effect. – King Chung Huang May 05 '11 at 15:06
  • The detail innertext is what I quoted in my question: “Value does not fall within the expected range.” My frustration has been that I get the same message no matter what I do. There doesn't seem to be a way (that I know of) to get any more details about which field value SharePoint thinks is not in range, or what the range it expects is. – King Chung Huang May 05 '11 at 15:07