Wednesday 18 April 2012

InfoPath Forms Server, Data Sources and Authentication



OK, So I put together a nice little InfoPath form, nothing too flash – it collects some data about a site and sub sites and then goes ahead and calls a web service to create the site, sub sites and sets permissions.

Problem is that while the form works fine in the InfoPath client if I try to use it as a browser enabled form in SharePoint (which I need to do) it fails to make the data connection calls.

It’s a permission thing, basically SharePoint doesn’t pass the user credentials to the web service so the web service denies the connection.

Trying to work around it, I first thought it was to do with form trust so I fully trusted the form which meant that when I deployed it it forced me to deploy it as an administrator approved form. In simple terms it saves the form on the file system, the administrator uploads it to the central form template library (Central Administration > Application Management > Manage Form Templates) and deploys it to a site collection. This puts a feature wrapper around the form and deploys it as a content type. Apply the content type to a library and hey presto…

So I did that and it still didn’t work, that’s when I figured it was authentication and not trust that was causing the issue.

Basically to use data connections in InfoPath Forms Server (IFS from now on) you will need to create a Universal Data Connection (UDC) and store it in a Data Connection Library (DCL)… ’nuff acronyms ;-)

  • UDC = a file that stores (in plain text!) authentication details and the details of the web service (or whatever) you need to connect with.

  • DCL = just like it sounds this is where you put the UDC


So how do you write a UDC?


There’s a decent overview here: http://blogs.msdn.com/infopath/archive/2006/10/02/Data-Connections-in-Browser-Forms.aspx and if you’re anything like me you’ll want to see an example so here we go:
<?xml version="1.0" encoding="UTF-8"?>
<?MicrosoftWindowsSharePointServices ContentTypeID="0×010100B4CBD48E029A4ad8B62CB0E41868F2B0"?>
<udc:DataSource MajorVersion="2" MinorVersion="0" xmlns:udc="
http://schemas.microsoft.com/office/infopath/2006/udc">
<udc:Name>CreateSite</udc:Name>
<udc:Description>CreateSite</udc:Description>
<udc:Type MajorVersion="2" MinorVersion="0" Type="WebService">
<udc:SubType MajorVersion="0" MinorVersion="0" Type=""/>
</udc:Type>
<udc:ConnectionInfo Purpose="ReadWrite">
<udc:WsdlUrl>
http://hp-vs-moss2007:555/HP.WebServices.CreateWorkspace.asmx?wsdl</udc:WsdlUrl>
<udc:SelectCommand>
<udc:ServiceUrl>
http://hp-vs-moss2007:555/HP.WebServices.CreateWorkspace.asmx</udc:ServiceUrl>
<udc:SoapAction>HP.WebServices.CreateWorkspace/Create</udc:SoapAction>
</udc:SelectCommand>
</udc:ConnectionInfo>
</udc:DataSource>

You’ll notice that in my example above there are no authentication details. Well…that’s because I forgot to put them in! And what I actually found was that simply by using the UDC method authentication started working, I haven’t had time to look into this but I assume this is because by the very virtue of using a UDC connection held in a SharePoint library PassThrough authentication is being used. I then started adding some cod ethat runs under elevated privileges and ran into some problems, so put the authentication details back in again ala:

How do you ‘do’ one of these DCL things?


That’s easy ;-) It’s just like a document library in SharePoint. Go the the root of your site collection (that usually a site like http://server/sites/xxxx) and click Site Actions then Data Connection Library, give it a name and hey presto.

Now upload your UDC to your DCL and remember to approve the UDC.

Getting it to work with Infopath


This bit is the simple bit

  1. You create a new data connection (Tools -> Data Connections -> New -> Search for Connections on MOSS -> Add your site -> Select the UDC)

  2. And then use it as you would any other data connection


So what have you achieved?


Well you’ve kind of abstracted web service and InfoPath form so you now need to go through the UDC to get to the web service calls, of course you can go direct to the web service for normal InfoPath forms but not for web based forms. Is it good thing? Not sure, I’ve read posts saying that it makes things better because your connections are in a central library and can be shared between forms and I guess that’s something but then I can secure my form library, web service, web application etc anyway so do I really need another layer of security?

Anyway, it’s the only way it works so you’re stuck with it for now.

 

No comments:

Post a Comment