3 Replies Latest reply on Apr 2, 2012 3:12 AM by Sumit_flex

    Calling functions from SOAP webservice. Can't access webservice functions.

    Sumit_flex

      Hi flex gurus,

       

      I am quite new to flex. I am working on an flex application where I am trying to remotely invoke a SOAP webservice which is a wsdl file from Adobe flex 4.6.

       

      I have authenticated the webservice(Basic Authentication Done) and got access to wsdl but I am unable to call the functions in it. I just want to pass the username and password for the user login to the service function which will give me the data useful for my application, but nothing is returned when the webservice function is called.

       

      I am totally blocked at this point. Please help me.

       

      Thanks in advance.

        • 1. Re: Calling functions from SOAP webservice. Can't access webservice functions.
          nareah

          Hi sumit try this...

          protected function login_clickHandler(event:MouseEvent):void

                      {

                          var webservice:WebService = new WebService;

                          webservice.useProxy = false;

                          webservice.LoginOperation.resultFormat = 'object';

                          webservice.ValidateUser.addEventListener(ResultEvent.RESULT,onSoapResult);

                          webservice.addEventListener(FaultEvent.FAULT, onSoapFault);

                          webservice.loadWSDL("your wsdl');

                          webservice.ValidateUser(StringUtil.trim(nameTxt.text),StringUtil.trim(passwordTxt.text), "?");

                      }

                     

                      protected function onSoapResult(event:ResultEvent):void

                      {

                          loginDetails = event.result as Boolean;

                          if(loginDetails == true){

                              trace("SUCCESS")

                          }

                          if(loginDetails == false){

                             trace("Failure")

                          }

                      }

          • 2. Re: Calling functions from SOAP webservice. Can't access webservice functions.
            Sumit_flex Level 1

            Thanx nareah,....

             

            I am using a httpservice component to invoke a service. Does this solution help me in that case??

            • 3. Re: Calling functions from SOAP webservice. Can't access webservice functions.
              Sumit_flex Level 1

              Below is my code snippet. But nothing is returned from th service, what is the problem???

               

              <?xml version="1.0" encoding="utf-8"?>

              <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

                      xmlns:s="library://ns.adobe.com/flex/spark" title="CheckWS" >

                 

                 

                  <fx:Script>

                      <![CDATA[

                          import flash.net.drm.AuthenticationMethod;

                         

                          import mx.collections.ArrayCollection;

                          import mx.messaging.messages.SOAPMessage;

                          import mx.rpc.AsyncToken;

                          import mx.rpc.events.FaultEvent;

                          import mx.rpc.events.ResultEvent;

                          import mx.rpc.http.HTTPService;

                          import mx.rpc.soap.AbstractWebService;

                          import mx.rpc.soap.Operation;

                          import mx.rpc.soap.SOAPFault;

                          import mx.rpc.soap.SOAPHeader;

                          import mx.rpc.soap.SOAPResult;

                          import mx.rpc.soap.WebService;

                          import mx.rpc.wsdl.WSDLBinding;

                          import mx.utils.Base64Encoder;

                              

                          public var resultdata:String;

                         

                         

                          private function send_data(service:mx.rpc.http.HTTPService):void {

                             

                              var encoder:Base64Encoder = new Base64Encoder();           

                              encoder.insertNewLines = false;           

                              encoder.encode("auth_usrname:auth_pswd");

                              service.headers = {Authorization:"Basic " + encoder.toString()};

                              service.send();

                              

                          }

                         

                          //protected function soapWS_resultHandler(event:ResultEvent):void

                          //{

                              // TODO Auto-generated method stub

                              /* var i:int;

                              var webresult:String=event.result.toString();

                              i = 0; */

                              /* var i:int;

                              resultdata = event.result.toString();

                              i = 0;

                          } */

                      ]]>

                  </fx:Script>

                 

                 

                  <fx:Declarations>

                      <!-- Place non-visual elements (e.g., services, value objects) here -->

                           

                      <s:HTTPService id="soapWS"

                                     url="My_Web_URL?wsdl" result="soapWS_resultHandler(event)" resultFormat="xml" useProxy="false" method="POST">

                         

                         

                          <s:request xmlns="">

                              <Username>{username.text}</Username>

                              <Password>{password.text}</Password>

                          </s:request>

                          <s:result >

               

                              <![CDATA[

                                  var i:int;

                                 

                                  dgUserRequest.visible = true;

                                                 

                                  var obj:Object = new Object();

                                  obj = event.result;

                              //    dgUserRequest.dataProvider = event.result.toString();

                              //    var str:String = new String();

                                  resultdata = obj.toString();

                                  i = 0;

                              ]]>                                                       

                          </s:result>

                      </s:HTTPService>

                     

                  </fx:Declarations>

                 

                  <s:Form x="20" y="10" width="100%">

                      <s:FormItem color="blue">

                          <s:Label text="Username" />    

                          <s:TextInput id="username"/>

                      </s:FormItem>

                      <s:FormItem color="blue">

                          <s:Label text="Password" />    

                          <s:TextInput id="password"/>    

                      </s:FormItem>

                      <s:FormItem color="yellow">

                          <s:Button label="Submit" click="send_data(soapWS)"/>

                      </s:FormItem>

                  </s:Form>

                 

                 

                  <s:DataGrid id="dgUserRequest" x="20" y="300"

                               dataProvider="{resultdata}" width="100%">

                      <s:columns>

                          <s:ArrayList>

                              <s:GridColumn dataField="password" headerText="Password" />

                              <s:GridColumn dataField="username" headerText="User Name"/>

                          </s:ArrayList>

                      </s:columns>

                  </s:DataGrid>

              </s:View>