ColdFusion:如何使用SharePoint的getListItems()

时间:2009-04-14 14:36:54

标签: web-services sharepoint coldfusion moss

有人知道如何从SharePoint列表中获取所有项目吗?

应该可以使用4个参数调用函数getListItems()

  • 一个用于存储信息的列表,
  • 查询的第二个,
  • 显示字段的第三个,
  • 第四个指定要返回的行数。

我的代码是:

<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#">

但我得到的只是错误信息:

  

无法找到参数为{{9BE74555-1150-4AC8-ADE7-EE52923D7CE8},3,...}的Web服务操作GetListItems。

Normaly你必须传递函数的xmlNodes,就像告诉here一样。

我也尝试过,但不知道如何制作xmlNode。 我的代码也是行不通的:

<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#">

我以正确的方式调用网络服务的方式是什么?

谢谢你, 凯文


编辑:感谢您的回答,我认为XML元素有效。

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

但现在我得到了一个“非法争论异常”(这很好,因为它告诉我,web服务正在响应;)):

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 : )>

编辑2:

这是我的新代码(4月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")>

<cfdump var="#xmlDoc#">

<cfset ndQuery = XmlParse("<Query><Where><Gt><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Gt></Where></Query>", true)>
<cfset ndViewFields = XmlParse("<ViewFields><FieldRef Name='ID' /><FieldRef Name='Title' /></ViewFields>", True)>
<cfset ndQueryOptions = XmlParse("<queryOptions xmlns:SOAPSDK9=""http://schemas.microsoft.com/sharepoint/soap/""><QueryOptions/></queryOptions>", True)>

<cfdump var="#ndQuery#">
<cfdump var="#ndViewFields#">
<cfdump var="#ndQueryOptions#">

<cfoutput>#XMLFormat(ndQuery)#</cfoutput><br>
<cfoutput>#XMLFormat(ndViewFields)#</cfoutput><br>
<cfoutput>#XMLFormat(ndQueryOptions)#</cfoutput><br>
<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">

错误消息是:

Cannot perform web service invocation GetListItems.
The fault returned when invoking the web service operation is:
java.lang.IllegalArgumentException: argument type mismatch

3 个答案:

答案 0 :(得分:2)

您能否使用以下示例:

<cfinvoke webservice="http://sharepointserver:16999/blog/_vti_bin/usergroup.asmx?wsdl" method="GetUserCollectionFromWeb" password="[pw]" username="[username]" returnvariable="listOfUsers"/>

<cfdump var="#listOfUsers#">

此外,SharePoint身份验证机制是基本身份验证吗?

答案 1 :(得分:1)

试试这个:

<!--- 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#">

可能没有必要显式传入XML根节点,Web Service也处理完整的XML文档对象。在这种情况下,以下调用也可能没问题:

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

编辑:Lists.GetListItems Method上的MSDN页面声明:

  

queryOptions 的:   为此传递空值   参数,包括空   QueryOptions元素如下。

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

所以,让我们试试这个:

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

编辑#2

可能还有一个完全不同的问题 - GetListItems()方法的最后一个参数是可选的,如果您不想传递GUID字符串,则应设置为null

不幸的是,您使用的调用语法无法表示省略的参数,CFML没有文字null。您必须将您的通话转换为更详细(但更灵活)的<cfinvoke> / <cfinvokeargument>风格:

<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">

在这方面更深入的阅读是关于talktree.com:
How to invoke a Web Service while omitting optional service method arguments

答案 2 :(得分:1)