Pass Entire InfoPath Form to Web Service (Not Submitting)
I have an InfoPath 2010 form that queries a web se开发者_开发技巧rvice. The web service is expecting the entire InfoPath form as an XML string parameter. By an XML string I mean the string on the format
<my:myFields xmlns:my=...>
<my:Name>UserName</my:Name>
...
</my:myFields>
The web service will then process the string and return a result to the InfoPath form.
I have tried to pass the root element, ".", but at the web service end I am receiving the values only formatted by \r\n and \t. Any idea on how to pass the XML tags and the values.
I have found a workaround by passing the list name and the form name to a web service. The web service, which is hosted in SharePoint, will then get the XML of the form.
Here is the code for reference:
public class InfoPathHelper
{
private string _listName;
private string _fileUrl;
public InfoPathHelper(string listName, string fileName)
{
_listName = listName;
_fileUrl = string.Format("{0}/{1}.xml", listName, fileName);
}
public string GetFormXml()
{
using (SPWeb web = SPContext.Current.Web)
{
SPList lib = web.Lists[_listName];
SPFile file = lib.RootFolder.Files[_fileUrl];
XmlDocument doc = new XmlDocument();
doc.Load(file.OpenBinaryStream());
return doc.OuterXml;
}
}
}
精彩评论