You cannot automatically submit structured XML data to a Web service in InfoPath 2003 (826989)
The information in this article applies to:
- Microsoft Office InfoPath 2003
- Microsoft Office InfoPath 2003, Service Pack 1 (SP1)
SYMPTOMSWhen you submit information from an InfoPath form to a Web service by using the built-in InfoPath submit functionality, you may experience one of the following symptoms: - You may receive an error message. The error message that you receive varies according to the information that is being submitted and to the coding of the method that is being invoked on the Web service.
- You may notice that unexpected data is submitted to the Web service.
This article also discusses the following: - How InfoPath submits data to a Web service.
- Two methods for submitting the contents of an InfoPath form to a Web service.
CAUSEWhen InfoPath submits data to a Web service, it submits the contents of the XML node that was selected as a parameter, but it does not submit the XML node itself. This generally works well. For example, you have a Web service method like the following: [WebMethod]
public void SendSampleString( string sampleString )
{
//Do something interesting with the sample string.
}
If you submit the following XML element to this Web service method, the sampleString parameter is filled with "Hello, World!" (as you expect).
<sampleElement>"Hello, World!"</sampleElement> Unfortunately, this behavior can make it difficult to submit XML nodes or the whole InfoPath form to a Web service. For example, you have a Web service method like the following:
[WebMethod]
public string SendXMLElement( System.Xml.XmlElement theElement )
{
//Report how many children the submitted node had.
return "Node with " + theElement.ChildNodes.Count + " children submitted.";
}
If you submit the example XML element to this method by using the built-in InfoPath submit functionality, the contents of the theElement parameter generate an error. This error occurs because only the contents of the XML element ("Hello, World!"), are sent to the Web service method. Because the string is not a valid XML element, the .NET Framework generates an error; the error message appears in InfoPath. A similar problem occurs if you try to submit the whole InfoPath form to the example Web service method. In this case, InfoPath submits all the child nodes of the InfoPath form, but does not submit the root node. This results in multiple top-level XML nodes being submitted. Because this is also not valid XML, the .NET Framework selects the first top-level XML node and uses it as the theElement parameter. All the other nodes are ignored, and this gives the appearance that they were not submitted. RESOLUTIONThis problem is corrected in Microsoft Office 2003 Service Pack 1. To resolve this problem, obtain the latest service pack for Microsoft Office 2003.
For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
870924
How to obtain the latest service pack for Office 2003
WORKAROUNDTo work around this problem, write a custom submit action in script. You can use either of the following methods: - Use a secondary data source to perform the submit operation.
- Write code that creates a custom SOAP message and that sends it to the Web service.
Use a Secondary Data source- On the Tools menu, click Secondary Data Sources.
- In the Secondary Data Sources dialog box, click Add.
- On the first page of the Data Source Setup Wizard, click Web Service, and then click Next.
- Enter the location of the Web service that you want to submit, and then click Next.
- Select the Web service method that you want to use, and then click Next.
- When InfoPath prompts you to select the field or group from the form that will be used to fill the parameters of the Web service method, leave the parameters blank, and then click Next.
- Click to clear the "Connect to this secondary data source when the form is opened" check box, click Finish, and then click OK to close the Secondary Data Sources dialog box.
- On the Tools menu, click Submitting Forms.
- In the Submitting Forms dialog box, click Enable Submit.
- In the Submit list, click Submit using Custom Script, and then click OK to open Microsoft Script Editor.
- In the XDocument::OnSubmitRequest method, use script like the following script to submit the whole form.
Note You can also submit individual elements in the form.try{
//Get a reference to the SendXMLElement secondary data source.
var objSendXMLElement = XDocument.GetDOM("SendXMLElement");
objSendXMLElement.setProperty( "SelectionNamespaces",
'xmlns:s1="http://joelallxp.microsoft.com/schema" ' +
'xmlns:s0="http://tempuri.org/" ' +
'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"' );
//Remove any data from the SendXMLElement secondary data source.
var objData = objSendXMLElement.selectSingleNode(
"/dfs:myFields/dfs:queryFields/s0:SendXMLElement/s0:theElement");
var objCurrentData = objData.selectNodes("@* | node()");
objCurrentData.removeAll();
//Clone the XDocument.
var objClonedDocument = XDocument.DOM.documentElement.cloneNode(true );
objData.appendChild( objClonedDocument );
//Call the "Query" method of the secondary data source to send the data.
XDocument.DataObjects("SendXMLElement").Query();
//Report the results of the submit.
XDocument.UI.Alert(
objSendXMLElement.selectSingleNode(
"/dfs:myFields/dfs:dataFields/s0:SendXMLElementResponse/s0:SendXMLElementResult").text );
eventObj.ReturnStatus = true;
}
catch(ex)
{
eventObj.ReturnStatus = false;
}
Write Code- On the Tools menu, click Submitting Forms.
- In the Submitting Forms dialog box, click Enable Submit.
- In the Submit list, click Submit using Custom Script, and then click OK to open Microsoft Script Editor.
- In the XDocument::OnSubmitRequest method, use script like the following script to submit the whole form.
Note You can also submit individual elements in the form.try
{
//Create a SOAP object.
var objSOAPConnector = new ActiveXObject("MSOSOAP.HttpConnector30");
//Set the EndPointURL property to point to the Web service.
objSOAPConnector.Property("EndPointURL") = "http://server/WebService1/Submit.asmx";
//Set the SoapAction property to point to the Web service method. You can find this URI
//in the WSDL file of the Web service.
objSOAPConnector.Property("SoapAction") = "http://tempuri.org/SendXMLElement";
objSOAPConnector.Connect();
//Begin construction of a SOAP message to send to the Web service.
objSOAPConnector.BeginMessage();
var objSOAPSerializer = new ActiveXObject("MSOSoap.SoapSerializer30");
objSOAPSerializer.Init( objSOAPConnector.InputStream );
objSOAPSerializer.startEnvelope();
objSOAPSerializer.startBody();
//Construct the structure that marks the method name and the parameter name
//that you are sending.
objSOAPSerializer.StartElement( "SendXMLElement", "http://tempuri.org/" );
objSOAPSerializer.StartElement( "theNode", "http://tempuri.org/" );
//Write out the XML of the document.
objSOAPSerializer.WriteXml( XDocument.DOM.documentElement.xml );
//Finish each element.
objSOAPSerializer.EndElement();
objSOAPSerializer.EndElement();
//Call EndMessage to complete the SOAP message and send it to the Web service method.
//This results in the Web service method being called.
objSOAPSerializer.endBody();
objSOAPSerializer.endEnvelope();
objSOAPConnector.EndMessage();
//Use a SoapReader to read the response from the Web service method .
var ResponseReader = new ActiveXObject("MSOSOAP.SoapReader30");
ResponseReader.Load( objSOAPConnector.OutputStream );
//If there was no error, return true.
if (ResponseReader.Fault != null)
{
eventObj.ReturnStatus = false;
throw "Error submitting data: " + ResponseReader.Fault.xml;
}
eventObj.ReturnStatus = true;
}
catch (ex)
{
XDocument.UI.Alert("Failed to submit document: " + ex.description);
}
STATUS
This behavior is by design.
This behavior is by design in Microsoft Office InfoPath 2003. This behavior is changed by Microsoft Office InfoPath 2003 Service Pack 1.
Modification Type: | Minor | Last Reviewed: | 7/28/2006 |
---|
Keywords: | kbtshoot kbprb kbBug KB826989 kbAudDeveloper |
---|
|