2011-05-10 61 views
1

我有一个查询Web服务的InfoPath 2010表单。 Web服务期望整个InfoPath表单作为XML字符串参数。通过XML字符串我的意思是在格式将整个InfoPath表单传递到Web服务(不提交)

<my:myFields xmlns:my=...> 
    <my:Name>UserName</my:Name> 
    ... 
</my:myFields> 

Web服务,然后将处理字符串和结果返回给InfoPath表单的字符串。

我尝试过传递根元素“。”,但在Web服务结束时,我收到的值仅由\ r \ n和\ t格式化。关于如何传递XML标签和值的任何想法。

回答

2

我已经通过将列表名称和表单名称传递给Web服务来找到解决方法。在SharePoint中托管的Web服务将获取表单的XML。

下面是参考代码:

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; 
     } 
    } 
}