I'm probably the last person on Earth to do this, but..."Hey, InfoPath let's
you call Web Services!" :-)
This is actually really slick if you just need something simple like a test client
for your .NET code...
public
class People : System.Web.Services.WebService
{
public class
Person {
private string
_name;
private int
_age;
public string
Name {
get { return
_name; }
set { _name = value;
}
}
public int
Age {
get { return
_age; }
set { _age = value;
}
}
}
[WebMethod]
public Person GetPerson(string
name) {
Person p = new Person();
p.Name = name;
p.Age = new Random().Next(21, 100);
return p;
}
}
- Open InfoPath 2003 and design a new form.
- Click New from Data Connection...
- The Data Connection Wizard starts. Click Web Service, then click
Next.
- Click Receive and submit data, then click Next.
- Enter the URL for the WSDL location (http://localhost/PersonService/People.asmx?WSDL),
then click Next.
- Select the operation (in this case GetPerson), then click Next.
- Enter a query name, then click Next.
- Again you are presented with a URL, but this time it is for the "submit
data". Leave the value the same, and click Next.
- Again you are presented with the operation list (in this case GetPerson)
to select, then click Next.
- Select field or group, click the Modify button on the right
side of the dialog box.
- In the Select a field or group dialog box, expand the queryFields and operation
tree and click on the parameter (in this case name), then click OK.
- In the wizard dialog, click the submit data as string checkbox, then
click Next.
- Click Finish
When the InfoPath form appears, there will be a region for query field and data
field.
- Simply drag the queryFields folder on the right window pane into the "drag
query fields here" region.
- When the dialog appears, click Selection with Controls.
- Do the same thing for the dataFields folder in the "drag query fields here
region."
- From the File menu, click Publish.
- Select a location to publish (in this case folder on this computer),
then click Next.
- Set the destination file name, click Next, then click Finish.
- Close the Wizard.
