I have a flex 4.6 application calling a web service that access a MS SQl server. I'm using (or trying to use) a web service I created. the web service seems to be working the XML being return looks OK but I'm getting the below error.
"XML parser failure: element is malformed. null"
I Google this error and did some research and what I gather, it is cause by how the XML is format coming from the web service.
I have written the web service in c# and I tested it, The service is retuning the following XML structure:
<root>
<pub>
<PublicationId>BIA-B0112</PublicationId>
<TargetPPODate>2012-02-28</TargetPPODate>
<TargetPPIDate>2012-03-13</TargetPPIDate>
<TargetRIPDate>2012-03-16</TargetRIPDate>
</pub>
</root>
the format don't look wrong to me, here my C# code that returns this.
// Connect to the database and run the query
SqlConnection conn = new SqlConnection(bldr.ToString());
SqlCommand cmd = new SqlCommand("AWFE.dbo.Connect_PubInfo");
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Clear();
cmd.Parameters.Add(new SqlParameter("@Pubid", BookName));
conn.Open();
cmd.Connection = conn;
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
ds.DataSetName = "root";
da.SelectCommand = cmd;
da.Fill(ds, "pub");
// Return the data as XML
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(ds.GetXml());
return xmlDoc;
and here is the action script I'm using:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:service1="services.service1.*"
width="529" height="322">
<fx:Script>
<![CDATA[
import com.adobe.serializers.utility.TypeUtility;
import mx.controls.Alert;
import mx.events.FlexEvent;
protected function dataGrid_creationCompleteHandler(event:FlexEvent):void
{
PubInfoResult.token = service1.PubInfo("FRP-Q0112");
}
]]>
</fx:Script>
<fx:Declarations>
<s:CallResponder id="PubInfoResult"/>
<service1:Service1 id="service1"
fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
showBusyCursor="true"/>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:TextInput id="BookCode" x="9" y="22"/>
<s:DataGrid id="dataGrid" x="75" y="95"
creationComplete="dataGrid_creationCompleteHandler(event)" requestedRowCount="4">
<s:columns>
<s:ArrayList>
</s:ArrayList>
</s:columns>
<s:typicalItem>
<fx:Object></fx:Object>
</s:typicalItem>
<s:AsyncListView list="{TypeUtility.convertToCollection(PubInfoResult.lastResult)}"/>
</s:DataGrid>
</s:WindowedApplication>
I'm new flex and web services so I'm having some trouble in this area , any help would be great.
What I did not do is set the return type of the service in the data service is flash builder, once I did that the error was fix. now I ran into another issue which I have to research. its now only retuning the root element of the return XML file, I need the data in the element..
thanks everyone for helping.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.