in

didierdanse.net

Site personnel de Didier Danse
Didier Danse's Personnal Website
Microsoft Most Valuable Professional SharePoint

didierdanse.net - Development News

SharePoint: A Proxy Web Service that allows the use of GetListItems in Lists.asmx from InfoPath

When you call the GetListItems method in Lists.asmx Web Service, you have to pass some XML parameters. These parameters are not well understood by the Web Service so the use of this Web Service can be difficult and maybe impossible.

XML parameters are written as strings in InfoPath window (I know that XML is just a string that follow some predefined rules).

image

This string which is encoded before pass it to the Web Service is no more understandable by the Web Service.

As the problem is find we can do some additional tests. Calling the Web Service from a .NET application can be done without any issue. According to this, there is a solution: create and use a Proxy Web Service (coded using the .NET platform) that will be deployed to SharePoint platform. This Proxy will convert the string to a real XML content.

    <WebMethod()> _
    Public Function GetListItems(ByVal listName As String, ByVal viewID As String, ByVal query As String, ByVal viewFields As String, ByVal rowLimit As String, ByVal queryOptions As String, ByVal webID As String) As XmlNode
        Dim service As SharePointListsWS.Lists = GetWebServiceInstance(webID)

        Dim queryElement As XmlNode = CreateNode("Query", query)
        Dim viewFieldsElement As XmlNode = CreateNode("ViewFields", viewFields)
        Dim queryOptionsElement As XmlNode = CreateNode("QueryOptions", queryOptions)

        Return service.GetListItems(listName, viewID, queryElement, viewFieldsElement, rowLimit, queryOptionsElement, webID)

    End Function

    Private Function GetWebServiceInstance(ByVal webID As String) As SharePointListsWS.Lists
        Dim service As New SharePointListsWS.Lists
        service.Credentials = System.Net.CredentialCache.DefaultCredentials

        service.Url = SPContext.Current.Web.Url + "/_vti_bin/Lists.asmx"

        Return service
    End Function

    Private Function CreateNode(ByVal name As String, ByVal innerXml As String)
        Dim document As New XmlDocument
        Dim node As XmlNode = document.CreateElement(name)
        node.InnerXml = innerXml
        Return node
    End Function

After having transform strings parameters to correct XML content, the Proxy Web Service will pass the XML parameters to Lists.asmx Web Service. This time GetListItems method is able to interpret the parameters. Values coming from the GetListItems method are returned directly to the client (in this case InfoPath).

If you want to code this Proxy Web Service, you have to know:

  • How to code a Web Service;
  • How to modify auto-generated elements to allow integration to SharePoint platform;
  • How to add this Web Service to SharePoint platform.

There is a few articles about each of these topics. If you don’t want to do all these points, you can just install the attached Web Service: Download

It is quite easy as you just have to:

  • Unzip the attached file;
  • Click on install.bat.

Attention! Be aware that the actual version of this package will erase and replace spdisco.aspx file. When uninstall the Web Service the file is deleted. You should test it on test environment before put it in production. Furthermore, you should backup the file before any other operation.

Comments

 

Oslo said:

Hi,

I tried to download the attached webservcie - but it has been removed... where can I download it from now?

Thanx

Onslow

May 28, 2009 8:11 AM
 

Didier Danse said:

Hi,

I modified the download link. You can use didierdanse.net/.../entry243.aspx

Didier

May 29, 2009 3:20 AM
 

Onslow said:

Thanks!

Can you help me understand another thing, when I create a dataconnection in InfoPath that point to this webservcie, to use the GetListsItem. How do I specify the parameters?

I understand (I hope) that for the listname and viewname I need to use the GUID, but the other parameters I do not know how to format. Do I have to set the sample fields as xml tags ?

I get an error "Object reference not set to an instance of an object."

I want the ID and Title from the view, and display them in a dropdown list box in InfoPath.

Thanks again for a quick reply

BR onslow

May 29, 2009 3:52 AM
 

Didier Danse said:

Sure, you have to use XML tags in Query and ViewFields parameters.

I can post or send you an complete sample this week end (I don't have enough time today to do this).

Feel free to send me an email to didier.danse @ gmail.com if you have more details about what you would like to do.

May 29, 2009 4:59 AM
 

Charles said:

This looks like it will solve the problems we have been having getting InfoPath and SharePoint to talk to one another.  Just one question: the new link to the installation doesn't include an install.bat.  How do I install this on my system?

Thanks,

Charles

June 2, 2009 6:33 PM

Leave a Comment

(required)  
(optional)
(required)  
Add
L'auteur du site ne peut être tenu responsable des dommages que les informations fournies pourraient entraîner. Tout est cependant mis en oeuvre pour éviter tout désagrément.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems