One of the nicest things InfoPath can do for a developer is aggregate Web Services and transparently present their functionality to use as secondary data sources. These data sources are great for binding drop down lists and populating repeating controls. However, they are not so great when we want to store the data they return and manipulate it later.
Calling Web Services from code is also usef when we run into situations in which the conditions under which we want to invoke a web method are too complex to define with rules. Also, this gives us the ability to call Web Services asynchronously in our form methods.
Although this is a rather straight-forward task for a .NET developer, there are a few nuances that InfoPath brings to the table. Here's how to do it:
In most cases, the following will work:
However, depending on IIS settings and other security mechanisms in place on the network, this might still fail. So use the following call to "force" successful web service authentication:
I've run into situations, especially when working with SharePoint web services, where the default credentials worked on a development server, but not in production. So, when working around .NET and Windows Server security, it never hurts to be as explicit as possible.
Finally, invoke the web methods (synchronously or asynchronously) in your form code, bypassing the limitations of using standard InfoPath web service implementations when they get in the way.