1 Reply Latest reply on Nov 21, 2007 11:22 AM by ntsiii

    Flex 2 and Java Webservice in Tomcat

    rsa4224
      Hello,

      I have created a simple webservice in java called Converter. I am trying to access it locally on a tomcat server from a flex application. For some reason I can not get this to work, am I missing something server side? The web service works if the client is jsp rather than flex. Please help!

      Here is the wsdl that is created:

      <?xml version="1.0" encoding="UTF-8"?>
      <wsdl:definitions targetNamespace=" http://app" xmlns:apachesoap=" http://xml.apache.org/xml-soap" xmlns:impl=" http://app" xmlns:intf=" http://app" xmlns:wsdl=" http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap=" http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd=" http://www.w3.org/2001/XMLSchema">
      <!--WSDL created by Apache Axis version: 1.4
      Built on Apr 22, 2006 (06:55:48 PDT)-->
      <wsdl:types>
      <schema elementFormDefault="qualified" targetNamespace=" http://app" xmlns=" http://www.w3.org/2001/XMLSchema">
      <element name="celsiusToFarenheit">
      <complexType>
      <sequence>
      <element name="celsius" type="xsd:float"/>
      </sequence>
      </complexType>
      </element>
      <element name="celsiusToFarenheitResponse">
      <complexType>
      <sequence>
      <element name="celsiusToFarenheitReturn" type="xsd:float"/>
      </sequence>
      </complexType>
      </element>
      <element name="farenheitToCelsius">
      <complexType>
      <sequence>
      <element name="farenheit" type="xsd:float"/>
      </sequence>
      </complexType>
      </element>
      <element name="farenheitToCelsiusResponse">
      <complexType>
      <sequence>
      <element name="farenheitToCelsiusReturn" type="xsd:float"/>
      </sequence>
      </complexType>
      </element>
      <element name="helloWorld">
      <complexType/>
      </element>
      <element name="helloWorldResponse">
      <complexType>
      <sequence>
      <element name="helloWorldReturn" type="xsd:string"/>
      </sequence>
      </complexType>
      </element>
      </schema>
      </wsdl:types>

      <wsdl:message name="helloWorldResponse">

      <wsdl:part element="impl:helloWorldResponse" name="parameters"/>

      </wsdl:message>

      <wsdl:message name="helloWorldRequest">

      <wsdl:part element="impl:helloWorld" name="parameters"/>

      </wsdl:message>

      <wsdl:message name="farenheitToCelsiusResponse">

      <wsdl:part element="impl:farenheitToCelsiusResponse" name="parameters"/>

      </wsdl:message>

      <wsdl:message name="farenheitToCelsiusRequest">

      <wsdl:part element="impl:farenheitToCelsius" name="parameters"/>

      </wsdl:message>

      <wsdl:message name="celsiusToFarenheitRequest">

      <wsdl:part element="impl:celsiusToFarenheit" name="parameters"/>

      </wsdl:message>

      <wsdl:message name="celsiusToFarenheitResponse">

      <wsdl:part element="impl:celsiusToFarenheitResponse" name="parameters"/>

      </wsdl:message>

      <wsdl:portType name="Converter">

      <wsdl:operation name="celsiusToFarenheit">

      <wsdl:input message="impl:celsiusToFarenheitRequest" name="celsiusToFarenheitRequest"/>

      <wsdl:output message="impl:celsiusToFarenheitResponse" name="celsiusToFarenheitResponse"/>

      </wsdl:operation>

      <wsdl:operation name="farenheitToCelsius">

      <wsdl:input message="impl:farenheitToCelsiusRequest" name="farenheitToCelsiusRequest"/>

      <wsdl:output message="impl:farenheitToCelsiusResponse" name="farenheitToCelsiusResponse"/>

      </wsdl:operation>

      <wsdl:operation name="helloWorld">

      <wsdl:input message="impl:helloWorldRequest" name="helloWorldRequest"/>

      <wsdl:output message="impl:helloWorldResponse" name="helloWorldResponse"/>

      </wsdl:operation>

      </wsdl:portType>

      <wsdl:binding name="ConverterSoapBinding" type="impl:Converter">

      <wsdlsoap:binding style="document" transport=" http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="celsiusToFarenheit">

      <wsdlsoap:operation soapAction=""/>

      <wsdl:input name="celsiusToFarenheitRequest">

      <wsdlsoap:body use="literal"/>

      </wsdl:input>

      <wsdl:output name="celsiusToFarenheitResponse">

      <wsdlsoap:body use="literal"/>

      </wsdl:output>

      </wsdl:operation>

      <wsdl:operation name="farenheitToCelsius">

      <wsdlsoap:operation soapAction=""/>

      <wsdl:input name="farenheitToCelsiusRequest">

      <wsdlsoap:body use="literal"/>

      </wsdl:input>

      <wsdl:output name="farenheitToCelsiusResponse">

      <wsdlsoap:body use="literal"/>

      </wsdl:output>

      </wsdl:operation>

      <wsdl:operation name="helloWorld">

      <wsdlsoap:operation soapAction=""/>

      <wsdl:input name="helloWorldRequest">

      <wsdlsoap:body use="literal"/>

      </wsdl:input>

      <wsdl:output name="helloWorldResponse">

      <wsdlsoap:body use="literal"/>

      </wsdl:output>

      </wsdl:operation>

      </wsdl:binding>

      <wsdl:service name="ConverterService">

      <wsdl:port binding="impl:ConverterSoapBinding" name="Converter">

      <wsdlsoap:address location=" http://localhost:8080/WebTest/services/Converter"/>

      </wsdl:port>

      </wsdl:service>

      </wsdl:definitions>


      Here is the mxml:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>
      <![CDATA[



      import mx.controls.Alert;
      import mx.rpc.events.ResultEvent;
      import mx.rpc.events.FaultEvent;
      import mx.rpc.soap.LoadEvent;
      import mx.collections.ArrayCollection;
      import mx.managers.CursorManager;
      import mx.utils.ArrayUtil;

      private namespace webXNameSpace = " http://app";
      use namespace webXNameSpace;



      ]]>
      </mx:Script>


      <!--create the WebService component-->
      <mx:WebService
      id="WS"
      wsdl=" http://localhost:8080/WTCOX_TEST/WebTest/WebContent/wsdl/Converter.wsdl"
      useProxy="false"
      showBusyCursor="true" >

      <!--specify the WebService method to use-->
      <mx:operation name="helloWorld" resultFormat="e4x" >
      <!--specify the values for the method parameters-->
      <mx:request>
      </mx:request>
      </mx:operation>
      </mx:WebService>

      <!--create user interface-->

      <mx:Panel>


      <mx:VBox >

      <mx:Label text="Example of Using MXML Tag mx:WebService" fontSize="14" textAlign="left">

      </mx:Label>
      <mx:Spacer height="10"/>
      <mx:Label text="Select a Number" fontSize="14" textAlign="left">

      </mx:Label>
      <mx:Spacer height="15"/>
      <mx:HBox>


      <mx:Label text="farenheit" width="101" fontSize="12"/>
      <mx:ComboBox id="c" fontSize="12">
      <mx:ArrayCollection>

      <mx:String>3</mx:String>
      <mx:String>6</mx:String>
      <mx:String>60</mx:String>

      </mx:ArrayCollection>

      </mx:ComboBox>
      </mx:HBox>
      <mx:Spacer height="25"/>

      <mx:HBox fontSize="12">


      <mx:Button label="Get Celsius" click="WS.helloWorld.send()"/>
      <mx:Label text="Celsius: " fontSize="12">

      </mx:Label>


      </mx:HBox>
      <mx:Spacer height="25"/>
      <mx:Label text="Complete XML Returned: "></mx:Label>
      <mx:HDividedBox width="800">
      <mx:TextArea id="myTextArea" text="{WS.helloWorld.lastResult.toXMLString()}" width="390" height="400" fontSize="12"/>
      </mx:HDividedBox>
      </mx:VBox>
      </mx:Panel>
      </mx:Application>