How to bind a Rich Text Box control to an element that is returned from a Web service in InfoPath 2003 and Visual Studio .NET (2003) (826996)
The information in this article applies to:
- Microsoft Office InfoPath 2003
- Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
- Microsoft Office InfoPath 2003, Service Pack 1 (SP1)
SUMMARYThis article describes how to bind a Rich Text Box control on a Microsoft Office InfoPath 2003 form to an XML element that is returned from a Web service. For a Rich Text Box control to bind to an XML element that is returned from a Web service, the Rich Text Box control must contain
XHTML content. The element must have the following XML schema: <xsd:element name="[elementname]">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:any namespace="http://www.w3.org/1999/xhtml" processContents="lax"
minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element> The <elementname> is the name of the XML element that is returned from the Web service. InfoPath can automatically detect if an element is an XHTML element by querying the element for a sample value when InfoPath connects to the Web service
data source for the first time. This article describes how to create a Web service that returns valid XHTML. This article also describes how to display the XHTML that is returned from the Web service in a Rich Text Box control on an InfoPath form. back to the topCreate the Web service- Start Microsoft Visual Studio .NET.
- On the File menu, click New, and then
click Project.
- In the Project Types list, click Visual C# Projects. In the Templates list, click ASP.NET Web
Service.
- In the Location box, type http://<SERVER>/RichTextService where
<SERVER> is the name of your Web server, and then click OK.
- Right-click Service1.asmx, and then click View Code.
- Add the following Web Service method to the Service1 class:
[WebMethod]
public System.Xml.XmlNode GetXHTMLRichText()
{
//Create a temporary XmlDocument object to generate nodes.
System.Xml.XmlDocument tempDocument = new System.Xml.XmlDocument();
//Create a wrapper node for the data. This is necessary so InfoPath
//correctly detects the XHTML content
System.Xml.XmlElement theNode = (System.Xml.XmlElement)tempDocument.CreateNode(
System.Xml.XmlNodeType.Element, "theNode", "http://somearbitrarynamespace/" );
//Create a "font" element in the xhtml namespace.
System.Xml.XmlElement theFontNode = (System.Xml.XmlElement)tempDocument.CreateNode(
System.Xml.XmlNodeType.Element, "font", "http://www.w3.org/1999/xhtml" );
theFontNode.InnerText= "Red Text";
//Add a color attribute.
System.Xml.XmlAttribute colorAttribute = tempDocument.CreateAttribute(
"color" );
colorAttribute.Value = "#ff0000";
theFontNode.Attributes.Append( colorAttribute );
//Append the font node to the wrapper node
theNode.AppendChild( theFontNode );
//Return the wrapper element.
return theNode;
} - On the Build menu, click Build Solution.
- Exit Visual Studio .NET.
back to the topCreate the InfoPath form- Start InfoPath.
- On the File menu, click Design a Form.
- In the Design a Form task pane, click New from Data Connection....
The
Data Source Setup Wizard starts. - Setup the data source as follows:
- Click Web Service for the data source, and then click Next.
- Click Receive data, and then click Next.
- Type http://<SERVER>/RichTextService/Service1.asmx for the location of the Web service, and then click Next.
- In the Select an operation list, click GetXHTMLRichText, and then click Next.
- Click Finish.
- Switch to the Data Source task pane, and then expand the dataFields group.
- Expand the GetXHTMLRichTextResponse group, and then move the GetXHTMLRichTextResult element to your form.
InfoPath adds a Rich Text Box
control to the view. back to the topTry it out- On the Task pane drop-down list, click Views.
- In the Views list, click Query. Right-click Query, and then click Set as Default.
- On the File menu, point to Preview Form, and then click Default.
- Click Run Query.
- On the View menu, click Data Entry.
Notice the value that is in the Rich Text Box control on the form. The value that is returned by the Web service is Red Text, and the value is formatted in red. back to the top
Modification Type: | Minor | Last Reviewed: | 10/21/2004 |
---|
Keywords: | kbHOWTOmaster kbWebServices kbhowto KB826996 kbAudDeveloper |
---|
|