Submit an InfoPath form to a web service and then retrieve return values

In this InfoPath demo video you will see how you can submit InfoPath form data to a web service and then retrieve and display any values that the web service sends back to the InfoPath form after it has been submitted.

In recipe 85, you'll learn how to write C# code in InfoPath 2010 and Visual Studio 2010 that enables a form to call a web service and retrieve any values the web service returns after data has been submitted to it.

Get more solutions from InfoPath 2010 Cookbook 3 which is available on
Watch next video: Select and add files from a document library as attachments to a form

InfoPath demo video transcript:

Here I'm in SharePoint 2010, and I've already published an InfoPath form template to this SharePoint form library.

The intention is that I can enter the name and color for an Office application and then when I hit Submit Record, this InfoPath form will call this web service, which in turn will go off to SQL Server and add a new record to this database table.

The web service will then grab the ID of the newly inserted record and return it back to the InfoPath form for display here in this Identifier text box along with the message of "Success". If the insert failed, the web service should return a -1 with a message describing the error that took place.

So if I go ahead and add an Office application... I'll add Outlook, color orange, and then I'll hit Submit Record. You'll see that an identifier of 50 will appear with the message of "Success". So that means that the record should have been inserted in the database.

So if I go to SQL Server and then refresh the data, you'll see that the record has indeed been added to the SQL Server database table.

Related InfoPath Demo Videos:

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent of S.Y.M. Wong-A-Ton. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author, S.Y.M. Wong-A-Ton.

InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers