<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Janne Mattila's blog : 2007 Office system</title><link>http://blogs.msdn.com/jannemattila/archive/tags/2007+Office+system/default.aspx</link><description>Tags: 2007 Office system</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Simple Outlook Add-in with VSTO 3.0</title><link>http://blogs.msdn.com/jannemattila/archive/2008/04/06/simple-outlook-add-in-with-vsto-3-0.aspx</link><pubDate>Sun, 06 Apr 2008 22:56:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8363721</guid><dc:creator>jannemattila</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/8363721.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=8363721</wfw:commentRss><description>&lt;p&gt;Creating add-ins with Visual Studio 2008 and VSTO 3.0 (Visual Studio Tools for Office) is easy and fast… Just use File –&amp;gt; New –&amp;gt; Project –&amp;gt; Select correct add-in i.e. Outlook 2007 Add-in and you project template is created. And you can run you add-in in debug by just hitting F5! So the basic setup is just few clicks and then you’re ready to start implementing your actual functionality i.e. extending ribbon etc.&lt;/p&gt; &lt;p&gt;In this post I’m going to create simple add-in that demonstrates how you can send emails on behalf of someone else and the selection for doing that is done automatically. Let’s go through the scenario since it’s easier to understand the functionality that way.&lt;/p&gt; &lt;p&gt;I have users John, Jane and Administrator. John wants to contact Jane but doesn’t know how to contact her so he sends out email to the administrator:&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;img border="0" alt="EmailToAdmin" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/EmailToAdmin_ca6d9d05-4ffa-42ea-90ac-ff69a17edb17.png" width="403" height="411"&gt; &lt;/p&gt; &lt;p&gt;Administrator receives mail from John:&lt;/p&gt; &lt;p&gt;&lt;img border="0" alt="EmailFromJohn" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/EmailFromJohn_9af3492b-0477-4c1d-974f-a17354bf5217.png" width="707" height="267"&gt;&lt;/p&gt; &lt;p&gt;Since Administrator knows Jane’s home phone he can contact her in urgent matters and get her message back to John. In this case Administrator just presses Reply to John’s email and writes the message as Jane dictates it over the phone:&lt;/p&gt; &lt;p&gt;&lt;img border="0" alt="EmailResponseToJohn" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/EmailResponseToJohn_12f3cbab-69ef-44cf-aecd-fc027cf5a65b.png" width="414" height="527"&gt; &lt;/p&gt; &lt;p&gt;John receives email that appears to be written by Jane:&lt;/p&gt; &lt;p&gt;&lt;img border="0" alt="EmailResponseAtJohnsOutlook" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/EmailResponseAtJohnsOutlook_caddf6bd-64d8-41b1-bdd8-69c5a51720bc.png" width="326" height="214"&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Okay that was our scenario and now let’s see how it was created. &lt;/p&gt; &lt;p&gt;Step 1: Well this is pretty obviously :-)&lt;/p&gt; &lt;p&gt;&lt;img border="0" alt="Addin1" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/Addin1_1ee85521-ed94-495c-bd7e-371019570cb7.png" width="543" height="308"&gt; &lt;/p&gt; &lt;p&gt;Step 2: Write following code (and as always.. &lt;u&gt;use this at your own risk&lt;/u&gt; :-). This should be extended with better error handling, sanity checks etc.):&lt;/p&gt; &lt;table cellspacing="10"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; Microsoft.Office.Interop.Outlook;
&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Windows.Forms;

&lt;font color="#0000ff"&gt;namespace&lt;/font&gt; My_Outlook_2007_Add_in
{
  &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;partial&lt;/font&gt; &lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#2b91af"&gt;ThisAddIn
&lt;/font&gt;  {
    &lt;font color="#2b91af"&gt;MailItem&lt;/font&gt; _mailItem = &lt;font color="#0000ff"&gt;null&lt;/font&gt;;
    &lt;font color="#0000ff"&gt;private&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; ThisAddIn_Startup(&lt;font color="#0000ff"&gt;object&lt;/font&gt; sender, System.&lt;font color="#2b91af"&gt;EventArgs&lt;/font&gt; e)
    {
      &lt;font color="#0000ff"&gt;this&lt;/font&gt;.Application.ItemLoad += &lt;font color="#0000ff"&gt;new
&lt;/font&gt;        &lt;font color="#2b91af"&gt;ApplicationEvents_11_ItemLoadEventHandler&lt;/font&gt;(Application_ItemLoad);
    }

    &lt;font color="#0000ff"&gt;void&lt;/font&gt; Application_ItemLoad(&lt;font color="#0000ff"&gt;object&lt;/font&gt; Item)
    {
      &lt;font color="#0000ff"&gt;if&lt;/font&gt; (Item &lt;font color="#0000ff"&gt;is&lt;/font&gt; &lt;font color="#2b91af"&gt;MailItem&lt;/font&gt;)
      {
        &lt;font color="#0000ff"&gt;try
&lt;/font&gt;        {
          &lt;font color="#2b91af"&gt;MailItem&lt;/font&gt; mailItem = Item &lt;font color="#0000ff"&gt;as&lt;/font&gt; &lt;font color="#2b91af"&gt;MailItem&lt;/font&gt;;
          mailItem.Open += &lt;font color="#0000ff"&gt;new&lt;/font&gt; 
            &lt;font color="#2b91af"&gt;ItemEvents_10_OpenEventHandler&lt;/font&gt;(mailItem_Open);
          _mailItem = mailItem;
        }
        &lt;font color="#0000ff"&gt;catch&lt;/font&gt; (System.&lt;font color="#2b91af"&gt;Exception&lt;/font&gt; ex)
        {
          &lt;font color="#2b91af"&gt;MessageBox&lt;/font&gt;.Show(ex.ToString(), 
            &lt;font color="#a31515"&gt;"Exception"&lt;/font&gt;, 
            &lt;font color="#2b91af"&gt;MessageBoxButtons&lt;/font&gt;.OK, &lt;font color="#2b91af"&gt;MessageBoxIcon&lt;/font&gt;.Error);
        }
      }
    }

    &lt;font color="#0000ff"&gt;void&lt;/font&gt; mailItem_Open(&lt;font color="#0000ff"&gt;ref&lt;/font&gt; &lt;font color="#0000ff"&gt;bool&lt;/font&gt; Cancel)
    {
      &lt;font color="#0000ff"&gt;if&lt;/font&gt; (_mailItem.Subject.Contains(&lt;font color="#a31515"&gt;"Jane"&lt;/font&gt;) == &lt;font color="#0000ff"&gt;true&lt;/font&gt;)
      {
        &lt;font color="#008000"&gt;// This requires "Send As" privileges at the AD:
&lt;/font&gt;        _mailItem.SentOnBehalfOfName = &lt;font color="#a31515"&gt;"&lt;/font&gt;&lt;font color="#a31515"&gt;jane@contoso.com&lt;/font&gt;&lt;font color="#a31515"&gt;"&lt;/font&gt;;
      }
    }

    &lt;font color="#0000ff"&gt;private&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; ThisAddIn_Shutdown(&lt;font color="#0000ff"&gt;object&lt;/font&gt; sender, System.&lt;font color="#2b91af"&gt;EventArgs&lt;/font&gt; e)
    {
    }

&lt;font color="#0000ff"&gt;    #region&lt;/font&gt; VSTO generated code
    &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;summary&amp;gt;
&lt;/font&gt;    &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; Required method for Designer support - do not modify
&lt;/font&gt;    &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; the contents of this method with the code editor.
&lt;/font&gt;    &lt;font color="#808080"&gt;///&lt;/font&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;font color="#808080"&gt;&amp;lt;/summary&amp;gt;
&lt;/font&gt;    &lt;font color="#0000ff"&gt;private&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; InternalStartup()
    {
      &lt;font color="#0000ff"&gt;this&lt;/font&gt;.Startup += &lt;font color="#0000ff"&gt;new&lt;/font&gt; System.&lt;font color="#2b91af"&gt;EventHandler&lt;/font&gt;(ThisAddIn_Startup);
      &lt;font color="#0000ff"&gt;this&lt;/font&gt;.Shutdown += &lt;font color="#0000ff"&gt;new&lt;/font&gt; System.&lt;font color="#2b91af"&gt;EventHandler&lt;/font&gt;(ThisAddIn_Shutdown);
    }
    
&lt;font color="#0000ff"&gt;    #endregion
&lt;/font&gt;  }
}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;Code works so that we first trap events from &lt;em&gt;ItemLoad&lt;/em&gt; (on line 11). In &lt;em&gt;Application_ItemLoad&lt;/em&gt; we check that is this current item &lt;em&gt;MailItem&lt;/em&gt; and if it is we then hook &lt;em&gt;Open&lt;/em&gt; event of that Item. And when mail item is opened we’ll check that does that contain &lt;em&gt;Jane &lt;/em&gt;at the subject. And if it does then we set the &lt;em&gt;SentOnBehalfOfName&lt;/em&gt; property for the mail item. &lt;u&gt;You need to modify contents between lines 37 and 41 to make this work in real life&lt;/u&gt;. I just made this as simple as possible. So probably adding few more checks isn’t bad idea :-)&lt;/p&gt;
&lt;p&gt;Step 3: Build, Test and when everything is working then Publish:&lt;/p&gt;
&lt;p&gt;&lt;img border="0" alt="Publish0" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/Publish0_f42db157-d347-4a40-80db-ec2d0fc1cfa4.png" width="301" height="191"&gt; &lt;/p&gt;
&lt;p&gt;Publishing wizard asks the location for the published files:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/Publish1_2.png" target="_blank"&gt;&lt;img border="0" alt="Publish1" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/Publish1_thumb.png" width="372" height="332"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/Publish2_2.png" target="_blank"&gt;&lt;img border="0" alt="Publish2" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/Publish2_thumb.png" width="372" height="332"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/Publish3_2.png" target="_blank"&gt;&lt;img border="0" alt="Publish3" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/Publish3_thumb.png" width="372" height="327"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;After that published location contains following files:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/Folder1_2.png" target="_blank"&gt;&lt;img border="0" alt="Folder1" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/Folder1_thumb.png" width="533" height="170"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;em&gt;Setup.exe &lt;/em&gt;installs the add-in. &lt;em&gt;Application Files&lt;/em&gt; folder contains subfolder for each version of the add-in (since it will be published to same location on update). You can actually control the check for new versions from VS (by default add-in checks for update once per week):&lt;/p&gt;
&lt;p&gt;&lt;img border="0" alt="VS" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/VS_3.png" width="505" height="348"&gt; &lt;/p&gt;
&lt;p&gt;&lt;br&gt;Now you can install the add-in for all the necassary users. Setup also knows about prerequisites (.NET framework 3.5 and VSTO 3.0 Runtime) and knows how to get them during install:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/PreReq1_2.png" target="_blank"&gt;&lt;img border="0" alt="PreReq1" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/PreReq1_thumb.png" width="302" height="357"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/PreReq2_2.png"&gt;&lt;img border="0" alt="PreReq2" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/PreReq2_thumb.png" width="302" height="360"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;And when prereqs are ok we’re ready to install our app (this screenshot is from Windows Server 2003):&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/Folder2_3.png" target="_blank"&gt;&lt;img border="0" alt="Folder2" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/Folder2_thumb.png" width="404" height="203"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;After the installation add-in can be seen in Add Remove Programs (and removed if needed):&lt;/p&gt;
&lt;p&gt;&lt;img border="0" alt="AddRemove" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/AddRemove_047d2bf4-89ab-4f8c-8964-f0df9a338fc3.png" width="348" height="135"&gt; &lt;/p&gt;
&lt;p&gt;Now your Outlook will work as described at the beginning of the post. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hmm… you might start wondering that isn’t there few security issues in this approach? How can administrator act as Jane and how that isn’t displayed at his Outlook? Well by default security forbids this kind of scenario but if this kind of approach is needed then you need to give permission to the users at the AD (&lt;strong&gt;Important note:&lt;em&gt; &lt;/em&gt;&lt;/strong&gt;I gave &lt;em&gt;Everyone&lt;/em&gt; permissions to “&lt;em&gt;Send As”&lt;/em&gt; but that is not the way to go in real life):&lt;/p&gt;
&lt;p&gt;&lt;img border="0" alt="AD" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/AD_ec3ccefa-ec5b-402f-aa6a-d47558e7ed84.png" width="482" height="556"&gt; &lt;/p&gt;
&lt;p&gt;And what does Outlook do then? In previous screenshots Outlook didn’t notify administrator about the &lt;em&gt;SentOnBehalfOfName&lt;/em&gt; property change. However if you add more email addresses to your email then Outlook refreshes the view to this:&lt;/p&gt;
&lt;p&gt;&lt;img border="0" alt="Outlook" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/SimpleOutlookAddinwithVSTO3.0_10CBD/Outlook_68e46237-e636-4c26-8be1-4dc7e00b1251.png" width="313" height="427"&gt; &lt;/p&gt;
&lt;p&gt;So Outlook added &lt;em&gt;From…&lt;/em&gt; field and it now clearly indicates that this message will be send as &lt;em&gt;Jane&lt;/em&gt;. Outlook just makes sure that user is aware of the senders change. Obviously our add-in could inform the end user with some kind of tooltip or something like that but I’ll leave those details to you.&lt;/p&gt;
&lt;p&gt;Well here was small example of Outlook add-in. I’ll probably come back to add-ins in near future so stay tuned… &lt;br&gt;&lt;br&gt;Anyways… Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8363721" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/2007+Office+system/default.aspx">2007 Office system</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Visual+Studio/default.aspx">Visual Studio</category></item><item><title>From InfoPath to Database via Web Service</title><link>http://blogs.msdn.com/jannemattila/archive/2007/10/25/from-infopath-to-database-via-web-service.aspx</link><pubDate>Thu, 25 Oct 2007 15:09:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5666456</guid><dc:creator>jannemattila</dc:creator><slash:comments>15</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/5666456.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=5666456</wfw:commentRss><description>&lt;p&gt;I have been asked to build this kind of example sooooo many times that now I really need to write this down :-) This stuff isn't rocket science but I have got so many emails about this so I just want to answer all those questions at once.&lt;/p&gt; &lt;p&gt;So I have previously &lt;a href="http://blogs.msdn.com/jannemattila/archive/2007/01/21/infopath-and-web-service-data-connection.aspx" target="_blank"&gt;written&lt;/a&gt; about getting data from web service to the InfoPath. Now I'm going to show you how can you create web service that stores the data from InfoPath to the database. Nothing fancy but just to give you some starting points if your planning to do this.&lt;/p&gt; &lt;p&gt;I'm not going to create new InfoPath form for this so I'll just re-use the &lt;a href="http://blogs.msdn.com/jannemattila/archive/2007/01/21/infopath-and-web-service-data-connection.aspx" target="_blank"&gt;previously created example&lt;/a&gt;. &lt;/p&gt; &lt;p&gt;I just added new method to my web service to handle insert of new employee:&lt;/p&gt; &lt;table cellspacing="10"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" align="right"&gt;&lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top"&gt;&lt;pre&gt;[&lt;font color="#008080"&gt;WebMethod&lt;/font&gt;]
&lt;font color="blue"&gt;public&lt;/font&gt; &lt;font color="blue"&gt;int&lt;/font&gt; AddNewEmployee(&lt;font color="#008080"&gt;Employee&lt;/font&gt; employee)
{
  &lt;font color="blue"&gt;int&lt;/font&gt; rowsAffected = 0;
  &lt;font color="blue"&gt;using&lt;/font&gt; (&lt;font color="#008080"&gt;SqlConnection&lt;/font&gt; conn = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;SqlConnection&lt;/font&gt;(&lt;font color="#aa2000"&gt;"..."&lt;/font&gt;))
  {
    &lt;font color="#008080"&gt;SqlCommand&lt;/font&gt; cmd = &lt;font color="blue"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;SqlCommand&lt;/font&gt;(&lt;font color="#aa2000"&gt;"INSERT INTO Employees "&lt;/font&gt; +
      &lt;font color="#aa2000"&gt;"(EmployeeNumber, Title, FirstName, LastName, Salary) "&lt;/font&gt; +
      &lt;font color="#aa2000"&gt;"VALUES(@EmployeeNumber, @Title, @FirstName, @LastName, @Salary)"&lt;/font&gt;, conn);

    cmd.Parameters.AddWithValue(&lt;font color="#aa2000"&gt;"@EmployeeNumber"&lt;/font&gt;, employee.EmployeeNumber);
    cmd.Parameters.AddWithValue(&lt;font color="#aa2000"&gt;"@Title"&lt;/font&gt;, employee.Title);
    cmd.Parameters.AddWithValue(&lt;font color="#aa2000"&gt;"@FirstName"&lt;/font&gt;, employee.FirstName);
    cmd.Parameters.AddWithValue(&lt;font color="#aa2000"&gt;"@LastName"&lt;/font&gt;, employee.LastName);
    cmd.Parameters.AddWithValue(&lt;font color="#aa2000"&gt;"@Salary"&lt;/font&gt;, employee.Salary);

    conn.Open();
    rowsAffected = cmd.ExecuteNonQuery();
  }

  &lt;font color="blue"&gt;return&lt;/font&gt; rowsAffected;
}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;It accepts the previously defined &lt;em&gt;struct&lt;/em&gt; as parameter and it then just puts it into the database. It can't be any simpler right :-) Just add your own connections string and create new database+table and you're good to go.&lt;/p&gt;
&lt;p&gt;In my InfoPath form I change the label of button from &lt;em&gt;Get employee data&lt;/em&gt; to &lt;em&gt;Insert new employee&lt;/em&gt;. Then I added new web service of type "&lt;em&gt;Retrieve data&lt;/em&gt;"... and not type "&lt;em&gt;Submit data&lt;/em&gt;". Why? Well because "&lt;em&gt;Retrieve data&lt;/em&gt;" has more ways to modify the parameters. I think that "&lt;em&gt;Submit data&lt;/em&gt;" type is quite limited on that. &lt;/p&gt;
&lt;p&gt;Of course I also needed to change the rule of the button too:&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:6e6f2b99-de2e-4d61-bf11-71e95f391d3d" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5664289/original.aspx" alt="" style="width:522px; height:455px;" /&gt;&lt;/div&gt;
&lt;p&gt;Notice that last action is &lt;em&gt;Show dialog box expression&lt;/em&gt;.. I just that to display the return value but of course that isn't necessary (and it's not supported by InfoPath Form Services anyway).&lt;/p&gt;
&lt;p&gt;Now I'm ready to take this for a test spin:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:173d3019-3f69-4f2e-82ce-11e010b51733" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5664357/original.aspx" alt="" style="width:656px; height:262px;" /&gt;&lt;/div&gt;&lt;br&gt;Pressing button will then give me this dialog:
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:27cb48a4-2d30-4863-9b0a-a0aee524a2bf" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5664380/original.aspx" alt="" style="width:324px; height:119px;" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And if I go to the database I'll see something like this:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:6960CE03-38FC-44df-87D4-FA4540212B06:f3fe5262-71d0-4a95-8869-8f99dee4ba07" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;img src="http://blogs.msdn.com/photos/jannemattila/images/5664397/original.aspx" alt="" style="width:572px; height:196px;" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Database verifies our story. So 1 new row with the data that I have typed into the InfoPath form has come up...&lt;/p&gt;
&lt;p&gt;This was quick intro how you can create whole chain from InfoPath to web service and then to database.&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5666456" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/2007+Office+system/default.aspx">2007 Office system</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/InfoPath/default.aspx">InfoPath</category></item><item><title>Transferring attachment file from Web Service to InfoPath</title><link>http://blogs.msdn.com/jannemattila/archive/2007/02/08/transferring-attachment-file-from-web-service-to-infopath.aspx</link><pubDate>Thu, 08 Feb 2007 09:21:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1624447</guid><dc:creator>jannemattila</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/1624447.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=1624447</wfw:commentRss><description>&lt;p&gt;I &lt;a title="InfoPath and Web Service data connection" href="http://blogs.msdn.com/jannemattila/archive/2007/01/21/infopath-and-web-service-data-connection.aspx" target="_blank"&gt;previously posted&lt;/a&gt; about InfoPath and Web Service data connections. Back then I didn't mention that you could use the same method to transfer InfoPath attachments as well. It's actually pretty straightforward thing. All you need&amp;nbsp;to do at the web service is wrap up you existing file data to InfoPath file attachment format and return it as BASE64 encoded. It sounds easy and it really is. Well enough talking... let's checkout the code!&lt;/p&gt; &lt;p&gt;First we need method that creates InfoPath attachment from byte array. It could be something like this:&lt;/p&gt;&lt;pre&gt; 1  &lt;font color="#0000a0"&gt;static public &lt;/font&gt;&lt;font color="#008080"&gt;String&lt;/font&gt; CreateInfoPathAttachment(&lt;font color="#008080"&gt;String &lt;/font&gt;fileName, &lt;font color="#0000a0"&gt;byte&lt;/font&gt;[] fileData)
 2  {
 3      &lt;font color="#008000"&gt;// This memory stream for InfoPath attachment buffer before Base64 encoding.
&lt;/font&gt; 4      using (MemoryStream ms = new MemoryStream())
 5      {
 6          &lt;font color="#0000a0"&gt;uint&lt;/font&gt; fileNameLength = (&lt;font color="#0000a0"&gt;uint&lt;/font&gt;)fileName.Length + 1;
 7          &lt;font color="#0000a0"&gt;byte&lt;/font&gt;[] fileNameBytes = &lt;font color="#008080"&gt;Encoding&lt;/font&gt;.Unicode.GetBytes(fileName);
 8
 9          &lt;font color="#0000a0"&gt;using&lt;/font&gt; (BinaryWriter bw = &lt;font color="#0000a0"&gt;new&lt;/font&gt; BinaryWriter(ms))
10          {
11              &lt;font color="#008000"&gt;// Write the InfoPath attachment signature. 
&lt;/font&gt;12              bw.Write(&lt;font color="#0000a0"&gt;new byte&lt;/font&gt;[] { 0xC7, 0x49, 0x46, 0x41 });
13
14              &lt;font color="#008000"&gt;// Write the default header information.
&lt;/font&gt;15              bw.Write((&lt;font color="#0000a0"&gt;uint&lt;/font&gt;)0x14); &lt;font color="#008000"&gt;// size
&lt;/font&gt;16              bw.Write((&lt;font color="#0000a0"&gt;uint&lt;/font&gt;)0x01); &lt;font color="#008000"&gt;// version
&lt;/font&gt;17              bw.Write((&lt;font color="#0000a0"&gt;uint&lt;/font&gt;)0x00); &lt;font color="#008000"&gt;// reserved&lt;/font&gt;
18
19              &lt;font color="#008000"&gt;// Write the file size.
&lt;/font&gt;20              bw.Write((&lt;font color="#0000a0"&gt;uint&lt;/font&gt;)fileData.Length);
21  
22              &lt;font color="#008000"&gt;// Write the size of the file name.
&lt;/font&gt;23              bw.Write((&lt;font color="#0000a0"&gt;uint&lt;/font&gt;)fileNameLength);
24  
25              &lt;font color="#008000"&gt;// Write the file name (Unicode encoded).
&lt;/font&gt;26              bw.Write(fileNameBytes);
27  
28              &lt;font color="#008000"&gt;// Write the file name terminator. This is two nulls in Unicode.
&lt;/font&gt;29              bw.Write(&lt;font color="#0000a0"&gt;new byte&lt;/font&gt;[] { 0, 0 });
30              bw.Write(fileData);
31          }
32          &lt;font color="#0000a0"&gt;return&lt;/font&gt; &lt;font color="#008080"&gt;Convert&lt;/font&gt;.ToBase64String(ms.ToArray());
33      }
34  }
&lt;/pre&gt;
&lt;p&gt;This code has been&amp;nbsp;"copy-pasted" mainly&amp;nbsp;from &lt;a title="How to encode and decode a file attachment programmatically by using Visual C# in InfoPath" href="http://support.microsoft.com/kb/892730" target="_blank"&gt;this source&lt;/a&gt;. However there is unnecessary code (=my opinion)&amp;nbsp;so I have changed it a little bit. I prefer using the existing &lt;em&gt;ToBase64String&lt;/em&gt; method (unlike in original code sample).&lt;/p&gt;
&lt;p&gt;Now all you need to do at you web service is to pass filename and data to the method and it creates BASE64 encoded string that can be returned to the InfoPath.&lt;/p&gt;&lt;pre&gt;1  ...
2  &lt;font color="#008080"&gt;String&lt;/font&gt; fileName;&lt;br&gt;3  DocumentContainer myDocument;
4  ...
5  &lt;font color="#0000a0"&gt;byte&lt;/font&gt;[] fileData = &lt;font color="#008080"&gt;File&lt;/font&gt;.ReadAllBytes(fileName);
6  myDocument.Size = fileData.Length;
7  myDocument.Document = CreateInfoPathAttachment(fileName, fileData);
8  &lt;font color="#0000a0"&gt;return&lt;/font&gt; myDocument;
&lt;/pre&gt;
&lt;p&gt;In my example I use similar approach as in my previous example. I have &lt;em&gt;Document&lt;/em&gt; struct that has (in this case) at least to fields: size and document. And in InfoPath I could map those fields exactly as I explained in my earlier&amp;nbsp;post. Now you just map &lt;em&gt;Document&lt;/em&gt; field to your InfoPath attachment and that's it:&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathWebserviceTransferringattachment_150C9/InfoPath1%5B1%5D.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 5px 0px; border-left: 0px; border-bottom: 0px" height="73" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathWebserviceTransferringattachment_150C9/InfoPath1_thumb%5B1%5D.png" width="163" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;br&gt;And what makes this really nice... it works also with Forms Services as well! Of course this idea could be also otherway around... so you could sent file from InfoPath to web service using the same underlying idea. In that case you should only parse the InfoPath attachment so that you get the original filename and filedata. Read more about this case in &lt;a title="Programmatically reading a file attachment from an Infopath form" href="http://www.cubido.at/Blog/tabid/176/EntryID/40/Default.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1624447" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/.NET+General/default.aspx">.NET General</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx">tips and tricks</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/2007+Office+system/default.aspx">2007 Office system</category></item><item><title>InfoPath and Web Service data connection</title><link>http://blogs.msdn.com/jannemattila/archive/2007/01/21/infopath-and-web-service-data-connection.aspx</link><pubDate>Sun, 21 Jan 2007 14:08:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1502296</guid><dc:creator>jannemattila</dc:creator><slash:comments>28</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/1502296.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=1502296</wfw:commentRss><description>&lt;p&gt;I have used InfoPath mainly with SharePoint and my experiences have been quite good. However I have always felt like something was missing... something that would really warm my developer heart. And I have found it! It's nice integration with Web Services. InfoPath can retrieve and submit data to the Web Services with just few lines of code for Web Service and few button clicks at the InfoPath. But if you're&amp;nbsp;creating serious application you should definitely create&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/XML_Schema"&gt;XML Schema&lt;/a&gt; that is shared with applications. It would be easy to use ready-made schema at the InfoPath and in your other applications as well. I'm just going to create small example that uses web services to get data to few fields at the InfoPath. In my experience it's fairly common that you have a lot of fields at the InfoPath and then you would like to autopopulate some of the fields based on some other fields. You probably want to get&amp;nbsp;your employee/customer/product&amp;nbsp;data from some of the back-end systems like &lt;a href="http://en.wikipedia.org/wiki/Enterprise_resource_planning"&gt;ERP&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Customer_relationship_management"&gt;CRM&lt;/a&gt;, etc. So this example demonstrates simple way of achieving that kind of functionality. I'm going to present&amp;nbsp;this development process in "&lt;em&gt;real world scenario&lt;/em&gt;". So it means that developer creates&amp;nbsp;web service and&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/User_interface"&gt;UI&lt;/a&gt; Designer creates the InfoPath&amp;nbsp;form (Warning! It may contain &lt;u&gt;sarcasm&lt;/u&gt;!).&amp;nbsp;But enough talking... Let's start hacking!&lt;/p&gt; &lt;h3&gt;1. Create web service to return employee data&lt;/h3&gt; &lt;p&gt;First we're going to create simple web service that returns some employee data (and now '&lt;em&gt;we&lt;/em&gt;' stands for person in developer role):&lt;br&gt;&lt;/p&gt;&lt;pre&gt; 1: &lt;font color="#0000ff"&gt;using&lt;/font&gt; System;
 2: &lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Web;
 3: &lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Web.Services;
 4: 
 5: &lt;font color="#0000ff"&gt;public class&lt;/font&gt; &lt;font color="#0080c0"&gt;Service&lt;/font&gt; : System.Web.Services.&lt;font color="#0080c0"&gt;WebService&lt;/font&gt; {
 6:     &lt;font color="#0000ff"&gt;public struct&lt;/font&gt; &lt;font color="#0080c0"&gt;Employee&lt;/font&gt; {
 7:         &lt;font color="#0000ff"&gt;public int&lt;/font&gt; EmployeeNumber;
 8:         &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0080c0"&gt;String&lt;/font&gt; Title;
 9:         &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0080c0"&gt;String&lt;/font&gt; FirstName;
10:         &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0080c0"&gt;String&lt;/font&gt; LastName;
11:         &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0080c0"&gt;Decimal&lt;/font&gt; Salary;
12:     }
13: 
14:     [&lt;font color="#0080c0"&gt;WebMethod&lt;/font&gt;]
15:     &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0080c0"&gt;Employee&lt;/font&gt; GetEmployee(&lt;font color="#0000ff"&gt;int&lt;/font&gt; employeeNumber) {
16:         &lt;font color="#0080c0"&gt;Employee&lt;/font&gt; employee = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#0080c0"&gt;Employee&lt;/font&gt;();
17:         employee.EmployeeNumber = employeeNumber;
18:         employee.Title = &lt;font color="#804000"&gt;"Developer"&lt;/font&gt;;
19:         employee.FirstName = &lt;font color="#804000"&gt;"John"&lt;/font&gt;;
20:         employee.LastName = &lt;font color="#804000"&gt;"Doe"&lt;/font&gt;;
21:         employee.Salary = 12345;
22:         &lt;font color="#0000ff"&gt;return&lt;/font&gt; employee;
23:     }
24: }&lt;/pre&gt;
&lt;p&gt;Of course your data should be retrieved from your favorite back-end system, but I'll just return some dummy data. Okay now we just compile (and deploy if necessary) our web service so it can be used by InfoPath. And copy the&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/WSDL"&gt;WSDL&lt;/a&gt; url because you need it later when dealing with the InfoPath form.&lt;/p&gt;
&lt;h3&gt;2. Create InfoPath form&lt;/h3&gt;
&lt;p&gt;If I would be really lazy I would use &lt;em&gt;Design a form template&lt;/em&gt; -&amp;gt; &lt;em&gt;Web Service&lt;/em&gt; since it's really straightforward if you want to retrieve and submit data with Web Services. But I'm just going to take &lt;em&gt;Design a form template&lt;/em&gt; -&amp;gt; &lt;em&gt;Blank&lt;/em&gt;. Because in many cases the &lt;a href="http://en.wikipedia.org/wiki/User_interface"&gt;UI&lt;/a&gt; designer&amp;nbsp;doesn't know much about programming. Designer just drag &amp;amp; drops the controls to the template and stops working with the template when it looks good (Note: this form is my handwriting&amp;nbsp;so it hasn't even seen any &lt;a href="http://en.wikipedia.org/wiki/User_interface"&gt;UI&lt;/a&gt; design experience :-). &lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/Designer1.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 5px 5px 5px 0px; border-right-width: 0px" height="155" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/Designer1_thumb.png" width="372" border="0"&gt;&lt;/a&gt; &lt;br&gt;After that designer gives the template to the developer. And developer&amp;nbsp;sees right away that designer didn't&amp;nbsp;think&amp;nbsp;about those pretty important things like&amp;nbsp;&lt;em&gt;schemas&lt;/em&gt; and &lt;em&gt;data sources&lt;/em&gt;.&amp;nbsp;&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/Datasource1%5B3%5D.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 5px 0px; border-right-width: 0px" height="230" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/Datasource1_thumb%5B1%5D.png" width="205" border="0"&gt;&lt;/a&gt; &lt;br&gt;&lt;/p&gt;
&lt;p&gt;Developer doesn't want to do any extra work so he just renames the controls so that they're are easily understandable. &lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath12%5B1%5D.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 5px 0px; border-left: 0px; border-bottom: 0px" height="240" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath12_thumb%5B1%5D.png" width="208" border="0"&gt;&lt;/a&gt; &lt;br&gt;After that developer changes the &lt;em&gt;Form Template Properties&lt;/em&gt; at the &lt;em&gt;File&lt;/em&gt; -&amp;gt; &lt;em&gt;Properties&lt;/em&gt;. And now developer is ready to add web service datasource to the InfoPath form.&lt;/p&gt;
&lt;h3&gt;3. Create Web Service datasource&lt;/h3&gt;
&lt;p&gt;&amp;nbsp;Under &lt;em&gt;Tools&lt;/em&gt; -&amp;gt; &lt;em&gt;Data Connections&lt;/em&gt; add new data connection:&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath1%5B3%5D.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 5px 0px; border-left: 0px; border-bottom: 0px" height="142" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath1_thumb%5B3%5D.png" width="404" border="0"&gt;&lt;/a&gt; &lt;br&gt;Select &lt;em&gt;Receive data&lt;/em&gt; and press Next.&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath2%5B3%5D.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 5px 0px; border-left: 0px; border-bottom: 0px" height="169" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath2_thumb%5B3%5D.png" width="382" border="0"&gt;&lt;/a&gt; &lt;br&gt;Select &lt;em&gt;Web service&lt;/em&gt; and press Next.&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath3%5B6%5D.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 5px 0px; border-left: 0px; border-bottom: 0px" height="119" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath3_thumb%5B6%5D.png" width="396" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;br&gt;Paste the url of the &lt;a href="http://en.wikipedia.org/wiki/WSDL"&gt;WSDL&lt;/a&gt; and press Next.&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath4%5B3%5D.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 5px 0px; border-left: 0px; border-bottom: 0px" height="135" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath4_thumb%5B3%5D.png" width="395" border="0"&gt;&lt;/a&gt; &lt;br&gt;Select &lt;em&gt;GetEmployee&lt;/em&gt; method from the list (it's the only one so easy selection :) and press Next.&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath5%5B3%5D.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 5px 0px; border-left: 0px; border-bottom: 0px" height="169" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath5_thumb%5B3%5D.png" width="358" border="0"&gt;&lt;/a&gt; &lt;br&gt;Take away selection from &lt;em&gt;Automatically retrieve data when form is opened &lt;/em&gt;and press Finish.&lt;/p&gt;
&lt;h3&gt;4. Create Rule to the button that uses the new datasource&lt;/h3&gt;
&lt;p&gt;Now we have managed to create connection to our web service. Let's add the &lt;em&gt;Rule&lt;/em&gt; to the button so that web service is called when user clicks the button. The &lt;em&gt;Rule&lt;/em&gt; will contain following phases:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Set parameter for the Web Service Call 
&lt;li&gt;Make the Web Service Call 
&lt;li&gt;Set field values for each field from the secondary datasource (=Web Service)&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Right click on the button and select &lt;em&gt;Properties&lt;/em&gt;. Click on the &lt;em&gt;Rules&lt;/em&gt; button and then click &lt;em&gt;Add &lt;/em&gt;button from the &lt;em&gt;Rules&lt;/em&gt; dialog. Write name of this new rule (like &lt;em&gt;Get employee data from Web Service&lt;/em&gt;).&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath6%5B3%5D.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 5px 0px; border-left: 0px; border-bottom: 0px" height="164" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath6_thumb%5B3%5D.png" width="389" border="0"&gt;&lt;/a&gt; &lt;br&gt;Then we need to add some &lt;em&gt;actions&lt;/em&gt; to the &lt;em&gt;rule&lt;/em&gt;. Just click &lt;em&gt;Add action&lt;/em&gt; button:&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath7%5B3%5D.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 5px 0px; border-left: 0px; border-bottom: 0px" height="152" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath7_thumb%5B3%5D.png" width="382" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;br&gt;Verify that your checkbox is &lt;em&gt;Set a field's value&lt;/em&gt; and then press button next to the &lt;em&gt;Field&lt;/em&gt; textbox. Then you can select the &lt;em&gt;employeeNumber &lt;/em&gt;from the &lt;em&gt;GetEmployee&lt;/em&gt; data source.&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath8%5B3%5D.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 5px 0px; border-left: 0px; border-bottom: 0px" height="183" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath8_thumb%5B3%5D.png" width="373" border="0"&gt;&lt;/a&gt; &lt;br&gt;After that you do the same for the &lt;em&gt;Value&lt;/em&gt; field. That was &lt;em&gt;phase 1&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Phase 2&lt;/em&gt; is really simple... just add new action for &lt;em&gt;Query using a data connection: GetEmployee&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Phase 3&lt;/em&gt; contains quite many button clicks... just create &lt;em&gt;Set a field's value&lt;/em&gt; actions for each value return from the Web Service field:&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath9%5B3%5D.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 5px 0px; border-left: 0px; border-bottom: 0px" height="241" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath9_thumb%5B3%5D.png" width="372" border="0"&gt;&lt;/a&gt; &lt;br&gt;Finally we have following &lt;em&gt;Actions&lt;/em&gt; in our &lt;em&gt;Rule&lt;/em&gt;:&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath10%5B3%5D.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 5px 0px; border-left: 0px; border-bottom: 0px" height="270" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath10_thumb%5B3%5D.png" width="340" border="0"&gt;&lt;/a&gt; &lt;br&gt;And now we're ready to test our form. Just press &lt;em&gt;Preview&lt;/em&gt; toolbar item. When form opens you can fill &lt;em&gt;Number&lt;/em&gt; field with some number and populate the other fields by pressing the &lt;em&gt;Get employee data&lt;/em&gt; button:&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath11%5B3%5D.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 5px 0px; border-left: 0px; border-bottom: 0px" height="166" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/infopath11_thumb%5B3%5D.png" width="392" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;br&gt;Fields are filled with the retrieved data from the Web Service.&lt;/p&gt;
&lt;h3&gt;Summary&lt;/h3&gt;
&lt;p&gt;Now you know howto create simple Web Service call from InfoPath. But you may wonder that how did those field names come from the web service &lt;em&gt;struct&lt;/em&gt; into the InfoPath form? Well if you look at the services &lt;a href="http://en.wikipedia.org/wiki/WSDL"&gt;WSDL&lt;/a&gt; you can see, that it contains definitions for the &lt;em&gt;Employee&lt;/em&gt; data structure:&lt;br&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/wsdl%5B8%5D.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 5px 0px; border-left: 0px; border-bottom: 0px" height="99" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/InfoPathandWebServicedatasource_B85B/wsdl_thumb%5B8%5D.png" width="365" border="0"&gt;&lt;/a&gt; &lt;br&gt;So it's really easy to create small &lt;em&gt;struct&lt;/em&gt; that contain the necessary datas you want to expose from your service. It's easy and fast, but more correct way would be using the schemas. See &lt;em&gt;Creating a web service for InfoPath from in 25 easy steps&lt;/em&gt; article from the links below. And of course posting the data to the web service would be exactly the same as this example. Just create new &lt;em&gt;Rule&lt;/em&gt; that first copies all values from the fields in the form to the datasource fields. And after that you just call the correct method from the datasource. Isn't it easy... I think it is.&lt;/p&gt;
&lt;p&gt;That was my InfoPath post this time. And maybe next time something completely different stuff :)&lt;br&gt;&lt;br&gt;Anyways... Happy hacking!&lt;br&gt;&lt;br&gt;J&lt;br&gt;&lt;/p&gt;
&lt;h3&gt;Links to similar resources&lt;/h3&gt;
&lt;p&gt;&lt;a title="http://www.developer.com/net/article.php/3082431" href="http://www.developer.com/net/article.php/3082431" target="_blank"&gt;Build a Custom SharePoint Web Service for Your InfoPath 2003 Documents&lt;/a&gt;&amp;nbsp;&lt;br&gt;-- Howto retrieve and submit data with &lt;em&gt;XmlDocument&lt;/em&gt; &lt;br&gt;&lt;br&gt;&lt;a title="http://blogs.msdn.com/philoj/archive/2005/11/08/490200.aspx" href="http://blogs.msdn.com/philoj/archive/2005/11/08/490200.aspx" target="_blank"&gt;Creating a web service for an InfoPath form in 25 easy steps&lt;/a&gt;&amp;nbsp;&lt;br&gt;-- Creates InfoPath form and then extracts &lt;a href="http://en.wikipedia.org/wiki/XML_Schema"&gt;XML Schema&lt;/a&gt; out of it (Note: Exporting source files in InfoPath 2007: File-&amp;gt;Save as Source Files). Then &lt;em&gt;xsd.exe&lt;/em&gt; is used to create &lt;em&gt;.cs&lt;/em&gt; -file. It's then added to Visual Studio and used when creating the web service. And developer can enjoy full support from &lt;em&gt;&lt;a href="http://en.wikipedia.org/wiki/IntelliSense"&gt;IntelliSense&lt;/a&gt;&lt;/em&gt;. &lt;br&gt;&lt;br&gt;&lt;a title="http://msdn2.microsoft.com/en-us/library/aa192516(office.11).aspx" href="http://msdn2.microsoft.com/en-us/library/aa192516(office.11).aspx" target="_blank"&gt;Querying and Updating a Database Using Web Services in InfoPath and ASP.NET&lt;/a&gt;&amp;nbsp;&lt;br&gt;-- Example that uses &lt;em&gt;DataSet&lt;/em&gt;s with InfoPath.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1502296" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx">tips and tricks</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/2007+Office+system/default.aspx">2007 Office system</category></item></channel></rss>