5 Replies Latest reply on Dec 16, 2009 12:31 PM by skippyflipjack

    Using credentials with a web service -- what our my options?

    JoshBeall Level 1
      Hi All,

      I'm trying to determine what options I have in regards to setting credential requirements on my web services. The two options seem to be:

      -Basic authentication
      -SOAP header authentication.

      I see that the WebService class has a "setCredentials" method, but I haven't had much success with it. Here's the documentation reference:
      http://livedocs.adobe.com/labs/flex/3/langref/mx/rpc/AbstractService.html#setCredentials()

      It says: "Set the credentials for the destination accessed by the service ... Note that services that use a proxy or a third-party adapter to a remote endpoint will need to setRemoteCredentials instead."

      Great, I'm not using a proxy, so I figured it would work. I thought I would try it with SOAP header auth. I setup a simple ASP.NET web service that users SOAP header auth, and decided to try it out. Attached is my complete MXML (I also tried using SSL). The Flash player threw the following error:

        • 1. Re: Using credentials with a web service -- what our my options?
          JoshBeall Level 1
          Hmm, it didn't attach my code or my error message. I believe this was caused by the way Adobe's forums uses sessions, and the fact that I had browser windows open in both the Flex 3 (labs) forum, and the Flex Support forum. Here's a retry. Error message:

          [MessagingError message='Authentication not supported on DirectHTTPChannel (no proxy).']
          at mx.messaging.channels::DirectHTTPChannel/setCredentials()
          at mx.messaging::ChannelSet/setCredentials()
          at mx.messaging::MessageAgent/setCredentials()
          at mx.rpc::AbstractService/setCredentials()
          at SoapHeaderAuthenticatedServicesTest/handleLoad()
          at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.rpc::AbstractService/dispatchEvent()
          at mx.rpc.soap::WebService/ http://www.adobe.com/2006/flex/mx/internal::wsdlHandler()
          at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.rpc.wsdl::WSDLLoader/private::checkLoadsOutstanding()
          at mx.rpc.wsdl::WSDLLoader/mx.rpc.wsdl:WSDLLoader::resultHandler()
          at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.rpc::AbstractInvoker/ http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()
          at mx.rpc::AbstractInvoker/ http://www.adobe.com/2006/flex/mx/internal::resultHandler()
          at mx.rpc::Responder/result()
          at mx.rpc::AsyncRequest/acknowledge()
          at private::DirectHTTPMessageResponder/completeHandler()
          at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at flash.net::URLLoader/flash.net:URLLoader::onComplete()
          at [io]

          Code:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete='onLoad(event)'>

          <mx:Script>
          <![CDATA[
          import mx.rpc.soap.*;
          public var service:WebService;

          public function onLoad(event:Event):void{
          service = new WebService();
          service.wsdl = " http://d-webservices.intranetserver/SoapHeaderAuthenticatedService.asmx?WSDL";
          service.addEventListener("load",handleLoad);
          service.addEventListener("fault",handleFault);
          service.addEventListener("result",handleResult);
          service.loadWSDL();
          }

          public function handleLoad(event:Event):void{
          resultLabel.text = "load complete... waiting...";
          service.setCredentials("TestUser","TestPassword");
          service.HelloWorld();
          }

          public function handleFault(event:Event):void{
          resultLabel.text = "Fault!";
          }

          public function handleResult(event:Event):void{
          resultLabel.text = "Got a result back! " + service.HelloWorld.lastResult;
          }

          ]]>
          </mx:Script>

          <mx:Panel layout="absolute" right="2" left="2" top="2" bottom="2" title="Testing SOAP header authentication...">
          <mx:Label x="23" y="19" text="And the result was:"/>
          <mx:Label x="156" y="19" text="waiting..." fontWeight="bold" id="resultLabel"/>
          </mx:Panel>
          </mx:Application>
          • 2. Re: Using credentials with a web service -- what our my options?
            huych02
            It looks like we are heading down the same path Josh. I can't get this to work either. I tried setCredentials and setRemoteCredentials and neither worked.

            The funny part is that I did manage to retrieve some data from the server at one point. I was using FireFox and in one tab I authenticated manually to view the WSDL. I loaded my SWF in another window and without any authentication it downloaded the information. I'm guessing it just shared the session between the two tabs.

            I switched over to using I.E. and have not found a way to authenticate through Flex.
            • 3. Re: Using credentials with a web service -- what our my options?
              andrew.morrison
              I'm having the same problem. There was a workaround posted somewhere that suggested rewriting the URL string with the credentials, as in:

              http://user:pass@127.0.0.1/api.php

              This is very non-optimal, however.
              • 4. Re: Using credentials with a web service -- what our my options?
                bpja
                Just tried the https://user:pass@host/ workaround....doesn't work.

                It appears that Flex deliberately says "no auth support unless you use the proxy"

                Why?
                • 5. Re: Using credentials with a web service -- what our my options?
                  skippyflipjack

                  I've found that http://user:pass@hostname.com/webservice/pass@hostname.com/webservice/ works for Firefox but not for IE/Safari.  It's irritating to find a browser-specific issue in what was supposed to be a cross-browser platform!  I have yet to find a workaround; as far as I've been able to tell, you can't get authentication-protected content from a remote server through Flex in IE or Safari.