简体   繁体   中英

Problem using flex to read XML in e4x format from SOAP webservice

UPDATE : The problem was not to do with namespaces or flex at all. My webservice was returning the wrapped xml. I was blaming the language I had least experience with before questioning the java...

I have a basic soap webservice that I am having trouble reading the result from in flex.

I'm a solid java programmer and just trying to get my head around adobe flex.

In the documentation I should be able to use "WebService" to return the result in e4x format.

    <mx:WebService id="CurrentLayersWS" wsdl="http://localhost:8080/myproject/ws/myservice.wsdl" showBusyCursor="true" result="updateSelected(event)" fault="Alert.show(event.fault.faultString), 'Error'">
      <mx:operation name="publisher" resultFormat="e4x">
        <mx:request>
         <publisherRequest>
           <getConfiguration/>
         </publisherRequest>
        </mx:request>
      </mx:operation>
    </mx:WebService>

As you can see, the response is handled by the function "updateSelected" which looks something like:

private function updateSelected(event:ResultEvent):void {
    var responseXml:XML = XML(event.result);

Unfortunately, the event object seems to nested and encoded strangely. When I step trough with the debugger I see that responseXml is of type XMLList containing one element (at index 0) of type XML which just contains the following xml:

<sch:temp xmlns:sch="http://www.mycompany.co.uk/myproject/schemas" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
&lt;ns2:publisherResponse xmlns:ns2="http://www.mycompany.co.uk/myproject/schemas"&gt;
    &lt;getConfigurationResponse&gt;
        &lt;configuration&gt;
        ...etc

Why is my xml nested inside a document with a root node "sch:temp"?

That is a namespace. I'm not sure why it is there, but, I had to deal with something similar after we started consuming .NET WebServices in one of our Flex applications. I simply had to reference the namespace in my ActionScript:

<mx:Script>
    <![CDATA[
        private namespace schNamespace = "http://www.mycompany.co.uk/myproject/schemas";

        use namespace schNamespace;
    ]]>
</mx:Script>

Try it...it may work.

The problem was not to do with namespaces or flex at all. My webservice was returning the wrapped xml. I was blaming the language I had least experience with before questioning the java...

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM