I wrote a web service that queries the users in certain groups and I bound a dropdown in my InfoPath form to it. The web service requires two values, the site name and the group name. In using the InfoPath Data Connection wizard I specified the values.

We now are looking to move this form to another server (from dev to staging to prod) and this form is going to become the base for about a dozen other forms, so changing this value manually every time will become a hassel at best.

I figured out how to update the webservice from the code behind, and send it the values I want to send it. Very effective and useful.

IMPORTANT First thing though, you need to stop the web service data connection from getting values on start up. That option is in the last screen of the data connection wizard.

Then, in the Form_Load use the similar code as below and blamo, you're off and running.

WebServiceConnection webservConn = (WebServiceConnection)DataConnections["ListGroupUsers"];

XmlDocument inputDoc = new XmlDocument();

inputDoc.LoadXml("<ListGroupUsers xmlns=\"http://site/\"><SiteURL>" + SPContext.Current.Web.Url + "</SiteURL><GroupName>Site Members</GroupName></ListGroupUsers>");

XPathNavigator inputNav = inputDoc.CreateNavigator();

XmlDocument outputDoc = new XmlDocument();

XPathNavigator outputNav = outputDoc.CreateNavigator();

XmlDocument errorDoc = new XmlDocument();

XPathNavigator errorNav = errorDoc.CreateNavigator();

//Need to specify the XPath to dump the results into, so grab the Web Service repsonse

XPathNavigator root = MainDataSource.CreateNavigator();

XPathNavigator node = root.SelectSingleNode("/dfs:myFields/dfs:dataFields/tns:ListGroupUsersResponse/tns:ListGroupUsersResult", NamespaceManager);

webservConn.Execute(inputNav,node,errorNav);

Hope this helps!