Generate_UDCX__WebSvc

This will generate a UDCX file to query a Web Service
Language:
PowerShell
Keywords:
UDCX
Code Snippet

Function Generate_UDCX__WebSvc( [Microsoft.SharePoint.SPList]$DataConnectionLibrary

                              , [System.String]$tFileName

                              , [System.String]$UdcName

                              , [System.String]$UdcDescription

                              , [System.String]$WsUrl_Wsdl

                              , [System.String]$WsUrl_Svc

                              , [System.String]$wsUrl_SoapAction

                              ) {

    if (!$DataConnectionLibrary.RootFolder.Files[$tFileName].Exists)

    {

 

        $ms = New-Object System.Io.MemoryStream

        $sw = New-Object System.Io.StreamWriter($ms)

 

        $sw.WriteLine([System.String]::Format("<?xml version=`"1.0`" encoding=`"UTF-8`"?>"))

        $sw.WriteLine([System.String]::Format("<?MicrosoftWindowsSharePointServices ContentTypeID=`"0x010100B4CBD48E029A4ad8B62CB0E41868F2B0`"?>"))                             # Data Connection

        $sw.WriteLine([System.String]::Format("<udc:DataSource MajorVersion=`"2`" MinorVersion=`"0`" xmlns:udc=`"http://schemas.microsoft.com/office/infopath/2006/udc`">"))    # v2 = InfoPath

        $sw.WriteLine([System.String]::Format(" <udc:Name>{0}</udc:Name>", $UdcName))

        $sw.WriteLine([System.String]::Format(" <udc:Description>{0}</udc:Description>", $UdcDescription))

        $sw.WriteLine([System.String]::Format(" <udc:Type MajorVersion=`"2`" MinorVersion=`"0`" Type=`"WebService`">"))

        $sw.WriteLine([System.String]::Format("       <udc:SubType MajorVersion=`"0`" MinorVersion=`"0`" Type=`"`"/>"))

        $sw.WriteLine([System.String]::Format(" </udc:Type>"))

        $sw.WriteLine([System.String]::Format(" <udc:ConnectionInfo Purpose=`"ReadOnly`" AltDataSource=`"`">"))

        $sw.WriteLine([System.String]::Format("       <udc:WsdlUrl>{0}</udc:WsdlUrl>", $WsUrl_Wsdl))

        $sw.WriteLine([System.String]::Format("       <udc:SelectCommand>"))

        $sw.WriteLine([System.String]::Format("             <udc:ListId/>"))

        $sw.WriteLine([System.String]::Format("             <udc:WebUrl/>"))

        $sw.WriteLine([System.String]::Format("             <udc:ConnectionString/>"))

        $sw.WriteLine([System.String]::Format("             <udc:ServiceUrl UseFormsServiceProxy=`"false`">{0}</udc:ServiceUrl>", $WsUrl_Svc))

        $sw.WriteLine([System.String]::Format("             <udc:SoapAction>{0}</udc:SoapAction>", $wsUrl_SoapAction))

        $sw.WriteLine([System.String]::Format("             <udc:Query/>"))

        $sw.WriteLine([System.String]::Format("       </udc:SelectCommand>"))

        $sw.WriteLine([System.String]::Format("       <udc:UpdateCommand>"))

        $sw.WriteLine([System.String]::Format("             <udc:ServiceUrl UseFormsServiceProxy=`"false`"/>"))

        $sw.WriteLine([System.String]::Format("             <udc:SoapAction/>"))

        $sw.WriteLine([System.String]::Format("             <udc:Submit/>"))

        $sw.WriteLine([System.String]::Format("             <udc:FileName>Specify a filename or formula</udc:FileName>"))

        $sw.WriteLine([System.String]::Format("             <udc:FolderName AllowOverwrite=`"`"/>"))

        $sw.WriteLine([System.String]::Format("       </udc:UpdateCommand>"))

        $sw.WriteLine([System.String]::Format("       <!--udc:Authentication><udc:SSO AppId='' CredentialType='' /></udc:Authentication-->"))

        $sw.WriteLine([System.String]::Format(" </udc:ConnectionInfo>"))

        $sw.WriteLine([System.String]::Format("</udc:DataSource>"))

        #$sw.WriteLine([System.String]::Format("")

        $sw.Flush()

 

        $tFileName_SiteRelativeUrl = $DataConnectionLibrary.RootFolder.Url + "/" + $tFileName

 

        Write-Host([System.String]::Format("Creating [{0}] : UDCX to Web Service [{1}]", $tFileName_SiteRelativeUrl, $WsUrl_Svc))

 

        # store file contents

        $tFile = $DataConnectionLibrary.RootFolder.Files.Add($tFileName_SiteRelativeUrl, $ms)

 

        # Update metadata (Title, ContentType), approve if necessary

        $tItem = $tFile.Item

        $tItem["Title"] = $tFileName

        $tItem["ContentTypeId"] = $DataConnectionLibrary.ContentTypes["Universal Data Connection File"].Id

        $tItem.Update()

 

        if ($tItem.ParentList.EnableModeration) {

            $tFile.Approve("")

        }

    }

 

} # Function Generate_UDCX__WebSvc

Example

Generate_UDCX__WebSvc $tWeb.Lists["DCL"] `
                      "GetGroupCollectionFromUser.udcx " `
                      "GetGroupCollectionFromUser " `
                      "Return list of SPGroup in which Username is a member" `

                      ( [System.String]::Format("{0}/_vti_bin/UserGroup.asmx?WSDL", $tWeb.Url.TrimEnd('/')) ) `

                      ( [System.String]::Format("{0}/_vti_bin/UserGroup.asmx",      $tWeb.Url.TrimEnd('/')) ) `

                      "http://schemas.microsoft.com/sharepoint/soap/directory/GetGroupCollectionFromUser"


Created 2012-03-22
comments powered by Disqus
Login