views:

2531

answers:

3

Hi,

does anybody know, how i could get all items from a SharePoint-List?

It should be possible to call the function getListItems() with 4 parameters. One for the list where the information is stored in. one for the query. the third for the displayed fields. and the fourth that specifies the number of rows to return.

My code is:

<cfobject webservice="http://sharepointserver:16999/blog/_vti_bin/SiteData.asmx?wsdl" name="siteDataService"
 password="pw"
 username="user"
 >

<cfset siteDataService.GetListItems(
 "{9BE74555-1150-4AC8-ADE7-EE52923D7CE8}", 
 "<Where><Lt><FieldRef Name=""ID"" /><Value Type=""Counter"">3</Value></Lt></Where>", 
 "<FieldRef Name=""ID"" /><FieldRef Name=""Title"" />", 
 "4"
 )>  

<cfset ServiceResponse = GetSOAPResponse(siteDataService)>
<cfdump var="#ServiceResponse#">

But all i get is that errormessage:

Web service operation GetListItems with parameters {{9BE74555-1150-4AC8-ADE7-EE52923D7CE8},3,,4} cannot be found.

Normaly you have to pass xmlNodes the the function, like it is told here.

I also tried that, but don't know exactly how to make a xmlNode. My code, that also doesn't work is this one:

<cfset xmlDoc = XmlNew()>
<cfset ndQuery = xmlElemNew(xmlDoc, "Query")>
<cfset ndViewFields = xmlElemNew(xmlDoc, "ViewFields")>
<cfset ndQueryOptions = xmlElemNew(xmlDoc, "QueryOptions")>

<cfset ndQuery = "<Where><BeginsWith><FieldRef Name='Name' /><Value Type='Text'>D</Value></BeginsWith></Where>">
<cfset ndViewFields = "<FieldRef Name='ID' />">
<cfset ndQueryOptions = "">

<cfset listsService.GetListItems(
 "{52D3A638-FA12-44E8-9C17-5FBCD2899199}", 
 "", 
 ndQuery, 
 ndViewFields, 
 "1", 
 ndQueryOptions, 
 ""
 )>

<cfset ServiceResponse = GetSOAPResponse(listsService)>
<cfdump var="#ServiceResponse#">

Is the way, i try to call the webservice the right way?

Thank you, Kevin


EDIT: Thank you for your answer, I think the XML elements work.

<cfset listsService.GetListItems(
    "{9BE74555-1150-4AC8-ADE7-EE52923D7CE8}", 
    "{1DD69D36-FD18-42B8-B57D-CCA49FD12AFE}", 
    ndQuery.xmlRoot, 
    ndViewFields.xmlRoot, 
    "1", 
    ndQueryOptions.xmlRoot,
    ""
)>

But now i get an "Illegal argument exception" (that's great, because it tells me, that the webservice is responding ;) ):

Cannot perform web service invocation GetListItems.

The fault returned when invoking the web service operation is:

'' java.lang.IllegalArgumentException: java.lang.ClassCastException@f70df9

The error occurred in D:\wwwroot\SharePoint-Tests\blog.cfm: line 83
81 :         "1", 
82 :         ndQueryOptions.xmlRoot,
83 :     ""
84 : )>

EDIT 2:

This is my new code (Avril 28.)

    <cfset xmlDoc = XmlNew()>
<cfset xmlDoc.xmlRoot = xmlElemNew(xmlDoc, "xmlRoot")>
<cfset xmlDoc.xmlRoot.Query = xmlElemNew(xmlDoc, "Query")>
<cfset xmlDoc.xmlRoot.ViewFields = xmlElemNew(xmlDoc, "ViewFields")>
<cfset xmlDoc.xmlRoot.QueryOptions = xmlElemNew(xmlDoc, "QueryOptions")> 


<cfset xmlDoc.xmlRoot.Query.XmlChildren[1] = xmlElemNew(xmlDoc, "Where")>
<cfset xmlDoc.xmlRoot.Query.where.XmlChildren[1] = xmlElemNew(xmlDoc, "GT")>
<cfset xmlDoc.xmlRoot.Query.where.gt.XmlChildren[1] = xmlElemNew(xmlDoc, "Value")>

0", true)> ", True)> ", True)>

#XMLFormat(ndQuery)#
#XMLFormat(ndViewFields)#
#XMLFormat(ndQueryOptions)#

<cfinvoke 
  webservice     = "#listsService#" 
  method         = "GetListItems"
  returnvariable = "result"
  timeout        = "10"
>
  <cfinvokeargument name="listName"     value="{9BE74555-1150-4AC8-ADE7-EE52923D7CE8}">
  <cfinvokeargument name="viewName"     value="">
  <cfinvokeargument name="query"        value="#ndQuery.XmlRoot#">
  <cfinvokeargument name="viewFields"   value="#ndViewFields.XmlRoot#">
  <cfinvokeargument name="rowLimit"     value="1">
  <cfinvokeargument name="queryOptions" value="#ndQueryOptions.XmlRoot#">
      <cfinvokeargument name="webID"        value="" omit="yes">

  <!--- setting "omit" to "yes" will turn the parameter to null --->
</cfinvoke>

<cfdump var="#result#" label="result">

The errormessage is:

Cannot perform web service invocation GetListItems. The fault returned when invoking the web service operation is:

'' java.lang.IllegalArgumentException: argument type mismatch

+1  A: 

Try this:

<!--- parse a bunch of XML documents, case-sensitively --->
<cfset ndQuery = XmlParse("<Where><BeginsWith><FieldRef Name='Name' /><Value Type='Text'>D</Value></BeginsWith></Where>", True)>
<cfset ndViewFields = XmlParse("<FieldRef Name='ID' />", True)>
<cfset ndQueryOptions = XmlParse("<QueryOptions />", True)>

<cfset listsService.GetListItems(
        "{52D3A638-FA12-44E8-9C17-5FBCD2899199}", 
        "", 
        ndQuery.XmlRoot, 
        ndViewFields.XmlRoot, 
        "1", 
        ndQueryOptions.XmlRoot, 

)>

<cfset ServiceResponse = GetSOAPResponse(listsService)>
<cfdump var="#ServiceResponse#">

Maybe it is unnecessary to explicitly pass in the XML root node, and the Web Service handles complete XML document objects just as well. In this case, the following call could also be fine:

<cfset listsService.GetListItems(
        "{52D3A638-FA12-44E8-9C17-5FBCD2899199}", 
        "",
        ndQuery, 
        ndViewFields, 
        "1", 
        ndQueryOptions, 
        ""
)>


EDIT: The MSDN page on Lists.GetListItems Method states:

queryOptions: To pass an empty value for this parameter, include an empty QueryOptions element as follows.

<queryOptions 
 xmlns:SOAPSDK9="http://schemas.microsoft.com/sharepoint/soap/"&gt;
   <QueryOptions/>
</queryOptions>

So, let's try this:

<cfset ndQueryOptions = XmlParse("<queryOptions xmlns:SOAPSDK9="http://schemas.microsoft.com/sharepoint/soap/"&gt;&lt;QueryOptions/&gt;&lt;/queryOptions&gt;", True)>


EDIT #2

There may also be a completely different problem - the last parameter of the GetListItems() method is optional and should be set to null if you don't want to pass a GUID string.

Unfortunately the calling syntax you use is incapable of expressing omitted parameters, and CFML has no literal null. You must convert your call to the more verbose (but more flexible) <cfinvoke>/<cfinvokeargument> style for this:

<cfobject 
  webservice = "http://sharepointserver:16999/blog/_vti_bin/Lists.asmx?wsdl"
  name       = "listsService"
  password   = "pw"
  username   = "user"
>

<cfinvoke 
  webservice     = "#listsService#" 
  method         = "GetListItems"
  returnvariable = "result"
  timeout        = "10"
>
  <cfinvokeargument name="listName"     value="{52D3A638-FA12-44E8-9C17-5FBCD2899199}">
  <cfinvokeargument name="viewName"     value="">
  <cfinvokeargument name="query"        value="#ndQuery.XmlRoot#">
  <cfinvokeargument name="viewFields"   value="#ndViewFields.XmlRoot#">
  <cfinvokeargument name="rowLimit"     value="1">
  <cfinvokeargument name="queryOptions" value="#ndQueryOptions.XmlRoot#">
  <cfinvokeargument name="webID"        value="" omit="yes">
  <!--- setting "omit" to "yes" will turn the parameter to null --->
</cfinvoke>

<cfdump var="#result#" label="result">

More in-depth reading in this regard is on talkingtree.com:
How to invoke a Web Service while omitting optional service method arguments

Tomalak
That code helped me a lot. But now i have an other problem. (Illegal argument exception)
RaveKev
Have you tried without the ".XmlRoot"? Does it make a difference?
Tomalak
Now i'm back from my holidays.I've tried your code from "Edit #2" but it also throws an exception.You could see it in my "Edit 2:"
RaveKev
+1  A: 

here is another simple demo..

http://dotnetdreamer.com/2009/06/04/moss-web-services-accessing-sharepoint-list-data/