Part 1: Configuring Sharepoint for forms server
Part 2: Creating a WCF web services to be used by the forms server
This article will discuss the creating and configuration of an Infopath form that will be run through Forms Server in Moss 2007.
Instead of storing the forms in a document library, it will store the data in a Sql Server database. The article will also discuss loading content into a form from Sql Server. We will use WCF as layer that communicates between Forms Server and Sql Server.
The reader might ask why one would want to create such a complicated framework around an Infopath form, when storing forms in a library is easy and supported out of the box. If you can use a document library, please do so. Its a lot easier, in every possible way. In fact I would recommend document libraries over this approach in most any situation.
There are a few cases where security policies might make using a document library as the central repository for all the forms.
Using WCF as the middle tier, allows very tight control over who may view and who may contribute a form. This was the case in the project where we developed this strategy.
Since we will be passing parameters, we need a tiny bit of code-behind in the form, so we develop the form in Visual Studio.Net 2005 with the Infopath extensions
The high level workflow will be:
- Creating the form in Visual Studio
- Connecting the Data Source to the web services
- Creating the Data Connection files
- Approving the new Data Connection files
- Integrating the Data Connection files with Infopath
- Setup the code behind to handle the parameters
- Saving the form to the local hard drive,
- Uploading the form to Sharepoint,
Creating the from in Visual Studio
Ensure that you have the Infopath tools for Visual Studio installed on your machine.
Head over to the New Projects, and select the InfoPath Form template.

Open up the manifest.xsf and add all the fields and logic you need.
Connecting the Data Source to the web services
We need to tell Infopath what web service we wish to use to load the data for the form.
Select Data Connections

Click add, and Click Submit data

We wish to use a web service

Enter the Url of the web service you created in Part 2

Select the appropriate method for retrieving the data

It takes one parameter, you need to assign where in the form, the method can retrieve the data from. (The web service method takes the parameter)

Click through and your done.
Click through and do the exact same thing for the submit data connection.
The screens are pretty much the same, just select the other method.
Ensure that you use the Xml Subtree option.
Creating the Data Connection files
Now we need to create the Data Connection files.
The data connection files tells Sharepoint, and Forms Server what urls the form is allowed to call. So basically its a security feature. These files can be hand coded and coupled together, but for simplicity just have Infopath generate them.
Go back to o data connections, and this time select Convert.

Enter the Url you prepared in Part 1

Approving the new Data Connection files
Now go to the Data Connection Library you setup in Part 1
Make sure you approve both of the new Data Connection files that were just created.
If the files are not approved they cannot be used later.
Integrating the Data Connection files with Infopath
This step has already been done behind the scenes for you in Infopath, using the Convert step.
Setup the code behind to handle the parameters
Add a Loading Events event handler.
In this event handler what we need to do is to read the parameter, and load data associated with that parameter.
Ensure that you update the xpath expression.
if (e.InputParameters.ContainsKey("id")) {
Guid token = new Guid(e.InputParameters["id"]);
this.DataSources[0].CreateNavigator().SelectSingleNode(@"Xpath to id field on form", this.NamespaceManager).SetValue(token);
this.DataConnections["Main query"].Execute();
}
Then add an event handler you link to the submit button on your form
this.DataConnections["Main submit"].Execute();
Saving the form to the local hard drive
Select Publish form template

Publish the file to your local hard drive.
Uploading the form to Sharepoint
You have to go to the Central administration for your Sharepoint box.
Navigate your way to Application Management, and then Manage Form Templates.
Click on Upload form template

Select the file you published from Visual Studio, hit upload.

Now navigate to the forms library where you wanted to access the form.
Go to Settings, and now you need to add the form you just uploaded to the Content Type for this forms library.
This will enable you to select the appropriate form when you hit New on this document library.