The following is a code snibbit which will allow you to store Infopath forms via WCF.

In this post I focus soley on the WCF aspects, in a later post I will talk about the configuration of the Infopath form in order to utilize the code.  

using System;

using System.Data;

using System.IO;

using System.ServiceModel;

using System.Xml;

 

[ServiceContract()]

[XmlSerializerFormat]

public interface IInfopathStorage

{

    [OperationContract]

    XmlDocument LoadForm(int id);

 

    [OperationContract]

    void StoreForm(XmlDocument xmlDoc, int id);

}

 

public class InfopathStorage : IInfopathStorage

{

    public XmlDocument LoadForm(int id)

    {

 

        XmlDocument xmlDoc = new XmlDocument();

        StringReader sr = new StringReader(MyDal.GetForm(id));

        xmlDoc.Load(sr);

        return xmlDoc;

    }

 

    public void StoreForm(XmlDocument xmlDoc, int id)

    {

        MyDal.StoreForm(xmlDoc, id);

    }

}

 

The most notable part of the code should be the [XmlSerializerFormat] attribute. This bit of magic will allow the passing of the XmlDocument object. Without the attribute you will get a compile time error stating that the XmlDocument cannot be serialized.

  <service name="InfopathStorage" behaviorConfiguration="returnFaults">
    <endpoint contract="IPersonalClientQuestionnaire" binding="basicHttpBinding"/>
   </service>

In your web.config file where you configure the WCF endpoints, its important to make sure your binding is set to basicHttpBidining, instead of wsHttpBiding. Otherwise Infopath will return errors.