39 Replies Latest reply on Nov 14, 2007 9:29 PM by lakhanpalv

    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 test it out. Attached is my complete MXML (I also tried using SSL). The Flash player threw the following error:

      [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]

      Interesting -- "Authentication not supported on DirectHTTPChannel (no proxy)" -- but the docs made it sound like that's precisely when you were to use setCredentials. If using a proxy, you would use setRemoteCredentials.

      So... what's up? How do I use setCredentials? And is it for use with SOAP header authentication, Basic authentication, or something else?
        • 1. Re: Using credentials with a web service -- what our my options?
          Peter Farland Level 3
          Hi Josh,

          Right, that documentation is misleading. For RPC services, like RemoteObject, WebService and HTTPService, the setCredentials() method is for authenticating with the FDS (now called LCDS) server before using the Proxy or Remoting services.

          setRemoteCredentials() is for the case where once you've successfully connected to FDS, the underlying service may then have to make a connection to a 3rd party, such as a data base or the actual remote service you're ultimately trying to contact (for the FDS Proxy Service, these remote credentials are automatically used to respond to HTTP Basic authentication challenges, for the FDS Remoting Service, the developer would have to use these credentials in their POJO as needed in completely custom code).

          So, both setCredentials() and setRemoteCredentials() are for use with FDS.

          To provide credentials to web services directly, it depends on the WSDL. Sometimes you see WSDLs that offer a login operation and these take a username and password as parameters. Other times you see operations requiring credentials in SOAP headers. Yet still further, other WebServices can make use of HTTP Basic authentication and thus you get a challenge dialog from the browser while communicating with the WebService. In the last case, this is something that is not really handled solely in a Flex UI. While it is true that you can try to pre-authenticate with HTTPServices (and unfortunately not yet with WebServices) by adding an Authorization HTTP header with a base-64 encoded set of credentials on the request, if the username and password are wrong you cannot intercept the challenge and ultimately you'll see the normal browser challenge dialog.

          Pete
          • 2. Re: Using credentials with a web service -- what our my options?
            JoshBeall Level 1
            quote:

            Originally posted by: pete
            ...Other times you see operations requiring credentials in SOAP headers...
            Pete


            This is what I'm currently pursuing. I did not have much success with Basic authentication (didn't work at all in IE, and, as you mentioned, even in browsers where it worked, if the username/password is wrong, the Flex UI can't intercept the login failure, and the user gets that ugly login popup).

            But, I'm not having much success. Here's what the SOAP request *should* look like, for my test web service that uses SOAP headers for authentication. I used a Visual Studio generated proxy class to make this call, and it returned the expected data from the web service (i.e., the SOAP authentication worked).

            <?xml version="1.0" encoding="utf-8"?>
            <soap:Envelope xmlns:soap=" http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=" http://www.w3.org/2001/XMLSchema">
            <soap:Header>
            <AuthHeader xmlns=" http://intranet/WebServices/">
            <UserName>TestUser</UserName>
            <Password>TestPassword</Password>
            </AuthHeader>
            </soap:Header>
            <soap:Body>
            <HelloWorld xmlns=" http://intranet/WebServices/" />
            </soap:Body>
            </soap:Envelope>

            Now, I want to set this up in Flex as well. Here's what I tried:



            // Called when the WSDL is finished loading
            public function handleLoad(event:Event):void{
            var qName : QName = new QName( " http://intranet/WebServices/", "AuthHeader" );
            var authXml : XML = <AuthHeader>
            <UserName>TestUser</UserName>
            <Password>TestPassword</Password>
            </AuthHeader>;
            var auth : SOAPHeader = new SOAPHeader( qName, authXml );
            service.addHeader(auth);
            service.HelloWorld();
            }

            No errors are thrown by Flex, however, the SOAP authentication fails (I get the expected "access denied" response from the web service). I used Wireshark to see what traffic was being sent back and forth, and this is what I see for the request from Flex:

            <SOAP-ENV:Envelope xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/" xmlns:s=" http://www.w3.org/2001/XMLSchema" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance">
            <SOAP-ENV:Header></SOAP-ENV:Header>
            <SOAP-ENV:Body>
            <tns:HelloWorld xmlns:tns=" http://intranet/WebServices/"/>
            </SOAP-ENV:Body>
            </SOAP-ENV:Envelope>

            Emphasis mine. Note that the SOAP header is empty -- what's going on?
            • 3. Re: Using credentials with a web service -- what our my options?
              Peter Farland Level 3
              Hi Josh,

              What exact version of Flex are you using? This is a known issue with certain versions of Flex - we've likely fixed this issue going forward and you could try one of the nightly builds for either Flex 2.0.1 or Flex 3 on Adobe Labs?

              Flex 2.0.1 nightly builds:
              http://labs.adobe.com/technologies/flex/sdk/flex2sdk.html

              Flex 3 nightly builds:
              http://labs.adobe.com/technologies/flex/sdk/flex3sdk.html

              If this issue is not fixed, we'll definitely want to get a bug logged to track this as it would be an important issue to fix. Flex bugs can be logged here:

              http://bugs.adobe.com/flex/

              Please let me know if this issue is not resolved. My email is pfarland@adobe.com.

              Regards,
              Pete
              • 4. Using credentials with a web service -- what our my options?
                JoshBeall Level 1
                I didn't try the nightly for 2.0.1, but the 2.0.1 Hotfix 2 SDK that I've already got exhibits the same behavior.

                It appears to be fixed with the latest nightly build of Flex 3. Authentication still isn't working, but I'm now seeing the username and password being passed through:

                <SOAP-ENV:Envelope xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/" xmlns:s=" http://www.w3.org/2001/XMLSchema" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance">
                <SOAP-ENV:Header>
                <tns:AuthHeader xmlns:tns=" http://intranet/WebServices/">
                <UserName>TestUser</UserName>
                <Password>TestPassword</Password>
                </tns:AuthHeader>
                </SOAP-ENV:Header>
                <SOAP-ENV:Body>
                <tns:HelloWorld xmlns:tns=" http://intranet/WebServices/"/>
                </SOAP-ENV:Body>
                </SOAP-ENV:Envelope>

                I'm noticing two things: "SOAP-ENV" everywhere that .NET simply uses "soap", and the "tns:" namespace. The proxy classes generated by Visual Studio do not use the "tns:" namespace anywhere.

                The "SOAP-ENV" vs "soap" thing doesn't seem to cause any problems (I'm guessing it's taken care of the by xmlns:SOAP-ENV or xmlns:soap declaration in the root element), but I i'm not sure what's up with the "tns:" prefixes/suffix. I think they are at the root of my problem. Is there a way to omit them entirely?
                • 5. Re: Using credentials with a web service -- what our my options?
                  Peter Farland Level 3
                  Sorry, I should have made it clear that the nightly builds for 2.0.1 are further on that 2.0.1 HF2, that is, they represent the latest code available, so you should use these nightly builds for 2.0.1 and replace HF2 with these later builds.

                  Did you mean that Authentication isn't working, but you _are_ now seeing the username and password being passed through (as they appear to be in your SOAP request example posted above)?

                  What the XML prefixes are themselves should not matter as they are arbitrary in qualified XML (so long as the namespace URI they represent is correct). The prefixes used are often chosen based on the prefixes used for the same namespace in the WSDL.

                  Instead of "tns" itself being the problem, it might be that these values are not expected to be qualified in the first place. I could take a quick look at the WSDL if you want to email it to me directly - pfarland@adobe.com.
                  • 6. Re: Using credentials with a web service -- what our my options?
                    JoshBeall Level 1
                    quote:

                    Originally posted by: pete
                    Did you mean that Authentication isn't working, but you _are_ now seeing the username and password being passed through (as they appear to be in your SOAP request example posted above)?


                    Oops, tthat's what I meant to say -- I had a typo, a "not" where I meant to have "now". I edited my message to fix it; sorry about that.

                    I emailed you the WSDL, along with the C# that defines the web service (in case that's of any value).

                    -Josh
                    • 7. Re: Using credentials with a web service -- what our my options?
                      JoshBeall Level 1
                      quote:

                      Originally posted by: pete
                      Sorry, I should have made it clear that the nightly builds for 2.0.1 are further on that 2.0.1 HF2, that is, they represent the latest code available, so you should use these nightly builds for 2.0.1 and replace HF2 with these later builds.


                      I snagged the latest nightly build (Fri Aug 17 2007), extracted the zip, and added it to the list of SDKs in Flex Builder. When i select that as the active SDK, though, I get an error on compile that simply says:

                      An internal build error has occurred. Please check the Error Log. WebServicesSandbox Unknown 1187807016506 300

                      I tried compiling by hand, and that seemed to work. So the bug seems to be resolved in the latest nightly builds of both Flex 2 and 3. I just need to figure out why the web service I've written doesn't seem to be "seeing" the SOAP header when called from Flex, but it does when called from ASP.NET (via a proxy class generated by Visual Studio).

                      -Josh
                      • 8. Re: Using credentials with a web service -- what our my options?
                        Peter Farland Level 3
                        (Note that "nightly builds" really depends on whether there were any changes to that version of the product... if no changes were made then there won't be a new build, and thus the last build will be at the top of the list).

                        I see what the problem is now - the issue is that you're manually creating the XML for your SOAP header, but since the elementFormDefault for this WSDLs schema is "qualified", your <UserName> and <Password> elements need to be qualified in that namespace too.

                        Try this in your AS3 code:
                        ...

                        var authXml : XML = <AuthHeader>
                        <UserName>TestUser</UserName>
                        <Password>TestPassword</Password>
                        </AuthHeader>;
                        var intranetNS:Namespace = new Namespace(" http://intranet/WebServices/");
                        authXML.setNamespace(intranetNS);

                        ...


                        Note that Namespace is a top-level built-in type of AS3. You can also specify a prefix if passing two String parameters to the constructor:

                        var intranetNS:Namespace = new Namespace("tns", " http://intranet/WebServices/");
                        • 9. Re: Using credentials with a web service -- what our my options?
                          JoshBeall Level 1
                          quote:

                          Originally posted by: pete
                          var authXml : XML = <AuthHeader>
                          <UserName>TestUser</UserName>
                          <Password>TestPassword</Password>
                          </AuthHeader>;
                          var intranetNS:Namespace = new Namespace(" http://intranet/WebServices/");
                          authXml.setNamespace(intranetNS);


                          Hmm... I tried that, and got no change in behavior. Then I tried this:

                          var authXml : XML = <AuthHeader>
                          <tns:UserName xmlns:tns=" http://intranet/WebServices/">TestUser</tns:UserName>
                          <tns:Password xmlns:tns=" http://intranet/WebServices/">TestPassword</tns:Password>
                          </AuthHeader>;
                          var auth : SOAPHeader = new SOAPHeader( qName, authXml );

                          That seemed to do the trick. Rather ugly, though, eh? If I omit the "xmlns:tns" attribute, the Flash player throws an error.

                          Is this the correct way to attach SOAP headers? Is there a simpler way? I'm looking forward to the proxy class generation that's coming to Flex Builder... will that make it easier to handle SOAP headers? Will I still be able to utilize SOAP headers?
                          • 10. Re: Using credentials with a web service -- what our my options?
                            Peter Farland Level 3
                            You should be able to set the namespace as I described to get it to generate the correct, qualified XML, you may have to experiment a bit with the syntax. But you should not need to specify the namespace on the E4X directly on each element.

                            As mentioned in another email, you don't have to construct this XML yourself. You should be able to provide the values to the SOAPHeader using an AS3 object...

                            var authHeader:Object = {UserName:username, Password:password};
                            var soapHeader:SOAPHeader = new SOAPHeader(qname, authHeader);
                            ...


                            Note that I don't think the Flex Builder wizard currently targets proxy class generation for SOAP headers? Might be worth trying out the next beta and logging an enhancement request (sorry that I'm not involved with that feature directly to know for sure).



                            • 11. Re: Using credentials with a web service -- what our my options?
                              JoshBeall Level 1
                              quote:

                              Originally posted by: pete
                              var authHeader:Object = {UserName:username, Password:password};
                              var soapHeader:SOAPHeader = new SOAPHeader(qname, authHeader);
                              Ah. Perfect. Sorry, I'm new to some of the AS syntax, so when you said "using an AS3 object" I was thinking: define a class, instantiate, populate values in class, and pass the class in." We don't have anonymous objects like that in .NET :-)


                              quote:

                              Originally posted by: pete
                              Note that I don't think the Flex Builder wizard currently targets proxy class generation for SOAP headers? Might be worth trying out the next beta and logging an enhancement request (sorry that I'm not involved with that feature directly to know for sure).
                              Well, Gabriel Dobritescu seemed to think it supportex proxy class generation *from* WSDL:
                              quote:

                              Originally posted by: GabiD.
                              Flex Builder 3 includes the "Import Web Service (WSDL)" wizard which is a tool that will generate proxy classes from a WSDL file. This tool is included in the latest engineering drop, but is not available in the latest beta build. ... Give these tools a try. We will appreciate any feedback you'll provide.

                              See complete thread



                              I'd love to give this tool a try, but I'm not sure where to get the release he's referring to. I suppose that whenever the next official Beta is released, it will be included? If there are nightly builds of some type that I can get access to, that would be great...
                              • 12. Re: Using credentials with a web service -- what our my options?
                                Peter Farland Level 3
                                Cool, right, the wizard is trying to generate proxy classes for the schema types and operations defined in the WSDL, but I'm not sure if it also includes headers? Headers are tricky as they don't have to be defined in the WSDL too...
                                • 13. Re: Using credentials with a web service -- what our my options?
                                  JoshBeall Level 1
                                  quote:

                                  Originally posted by: pete
                                  Cool, right, the wizard is trying to generate proxy classes for the schema types and operations defined in the WSDL, but I'm not sure if it also includes headers? Headers are tricky as they don't have to be defined in the WSDL too...


                                  Ah, I see.

                                  Well, so long as we are still able to attach headers using some method I think we'll be ok. I've now got my auth header code down to 3 lines

                                  var qName : QName = new QName( " http://intranet/WebServices", "AuthHeader" );
                                  var authHeader:Object = {UserName:"TestUser", Password:"TestPassword"};
                                  var auth : SOAPHeader = new SOAPHeader( qName, authHeader );

                                  Do you know if I will be able to attach headers via a similar method for proxy classes generated by the wizard?
                                  • 14. Re: Using credentials with a web service -- what our my options?
                                    Peter Farland Level 3
                                    I don't know off the top of my head, but I imagine it will be a requirement.
                                    • 15. Re: Using credentials with a web service -- what our my options?
                                      aks111
                                      Hello Josh,
                                      It seems like you were finally able to send a soap header successfully from Flex 2 to ASP.NET web service. I am struggling with the exact same issue since yesterday but have not been able to resolve it. Please see the attached MXML code for the Flex client app.

                                      My web service is an ASP.NET web service. It works just fine with an ASP.NET client but with a Flex client, the soap header is always null. The webservice works fine from Flex, its just that it's not receiving the soap header when called from Flex.

                                      The web method looks like this:
                                      [WebMethod]
                                      [SoapHeader("securityHeader", Direction = SoapHeaderDirection.In)]
                                      public string GetData()
                                      {
                                      if (securityHeader != null)
                                      {
                                      if(securityHeader.SecurityToken = "xyz")
                                      //do something to get the required data...
                                      }
                                      }

                                      securityHeader is an instance of the class SecurityHeader that is derived from System.Web.Services.Protocols.SoapHeader class. It has one property called SecurityToken.

                                      I would appreciate if you have any thoughts/suggestions.

                                      Thanks.
                                      • 16. Re: Using credentials with a web service -- what our my options?
                                        Peter Farland Level 3
                                        You're using Flex 2, right, if so what exact version? You can find out by opening rpc.swc in WinZip and looking for a catalog.xml. In here there should be a version section.

                                        Have you looked at the SOAP request using an HTTP sniffer? Any chance you could capture this and email it to me at pfarland@adobe.com?

                                        • 17. Re: Using credentials with a web service -- what our my options?
                                          aks111 Level 1
                                          Hello Pete,

                                          Thanks for responding. The version number in catalog.xml is 2.0.1. I would like to mention here that I have installed Flex 2 Hotfix 2 as well as Hotfix 3.

                                          I am trying to see the SOAP request using Wireshark. I am new to Wireshark and still trying to figure out how to get this information. I will send it to you as soon as I get it.

                                          One more peice of information that may be of value here is that the Flex app as well as the web service are running on my local machine.

                                          Ajay
                                          • 18. Re: Using credentials with a web service -- what our my options?
                                            Peter Farland Level 3
                                            Wireshark is sort of overkill for this sort of debugging, you could try something simpler like Charles, Paros Proxy, or even sniffer.exe from Axis which ships with JRun, FDS, etc. too. But alternatively, you could also add <mx:TraceTarget level="0" /> to your MXML and then run your application in the debug Flash Player and either look at the console in Flex Builder or look at flashlog.txt for the debug output. It should show you the SOAP request that was sent.

                                            You may also want to try the latest nightly build of Flex 2.0.1 to get an updated rpc.swc. See http://labs.adobe.com/technologies/flex/sdk/flex2sdk.html
                                            • 19. Re: Using credentials with a web service -- what our my options?
                                              aks111 Level 1
                                              You are right. I could see the soap envelop using <mx:Trace>. Here is what the Soap Header looks like.
                                              <SOAP-ENV:Header>
                                              <ns0:SecuritySoapHeader xmlns:ns0=" http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                                              <SecurityToken>123</SecurityToken>
                                              </ns0:SecuritySoapHeader>
                                              </SOAP-ENV:Header>

                                              This means the soap header does contain my SecurityToken. But when it reaches the web service, it does not see the header! This is confusing because it does see the soap header when I call the webservice from an ASP.NET client. Could it have anything to do with the value of the xmlns attribute of the ns0:SecuritySoapHeader element?

                                              Ajay
                                              • 20. Re: Using credentials with a web service -- what our my options?
                                                Peter Farland Level 3
                                                I think the problem might be that the <SecurityToken> element needs to be in the same namespace as the SecuritySoapHeader. This issue sounds familiar and I believe we've fixed it, but that may have been only for Flex 3. To confirm you could try a later nightly build of Flex 2.0.1 from the Adobe Labs website I mentioned earlier which would represent hotfixes even after HF3.

                                                As an alternative, you could try pre-encoding the SOAP header yourself using the E4X syntax inline for a variable of type XML?

                                                var securityHeader:XML = <ns0:SecuritySoapHeader xmlns:ns0=" http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                                                <ns0:SecurityToken>123</ns0:SecurityToken>
                                                </ns0:SecuritySoapHeader>;

                                                • 21. Re: Using credentials with a web service -- what our my options?
                                                  KillDash9
                                                  quote:

                                                  Originally posted by: pete
                                                  I think the problem might be that the <SecurityToken> element needs to be in the same namespace as the SecuritySoapHeader. This issue sounds familiar and I believe we've fixed it, but that may have been only for Flex 3. To confirm you could try a later nightly build of Flex 2.0.1 from the Adobe Labs website I mentioned earlier which would represent hotfixes even after HF3.

                                                  As an alternative, you could try pre-encoding the SOAP header yourself using the E4X syntax inline for a variable of type XML?

                                                  var securityHeader:XML = <ns0:SecuritySoapHeader xmlns:ns0=" http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                                                  <ns0:SecurityToken>123</ns0:SecurityToken>
                                                  </ns0:SecuritySoapHeader>;




                                                  As you can see, WS-Security is something that MANY Flex developers want to use when connecting to their web services. Unfortunately, it doesn't seem that there are plans to include WS-Security support in Flex 3. This is very disappointing.

                                                  Any work-arounds Adobe can provide would be much appreciated. Perhaps an article and/or example code?

                                                  Thanks.
                                                  • 22. Re: Using credentials with a web service -- what our my options?
                                                    lakhanpalv
                                                    Hi Pete,

                                                    I am also trying what JoshBeall has done. Trying to set credential. I am using Flex Builder 3 beta 2.
                                                    Here is the sample code of my app:

                                                    code:
                                                    ------------------------------------------------------------------------------------------ ------------------
                                                    <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://192.168.17.26/Wiziq_Latest/Flex/WebService/TestService.asmx?WSDL";
                                                    service.addEventListener("load",handleLoad);
                                                    service.addEventListener("fault",handleFault);
                                                    service.addEventListener("result",handleResult);
                                                    service.loadWSDL();
                                                    }

                                                    public function handleLoad(event:Event):void{
                                                    var qName:QName = new QName( " http://soapinterop.org/xsd", "AuthHeader" );
                                                    var authHeader:Object = {userName:"TestUser", Password:"TestPassword"};
                                                    var auth:SOAPHeader = new SOAPHeader(qName, authHeader);
                                                    service.addHeader(auth);
                                                    service.Test();
                                                    }

                                                    public function handleFault(event:Event):void{

                                                    resultLabel.text = "Fault!";
                                                    }

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

                                                    ]]>
                                                    </mx:Script>
                                                    <mx:TraceTarget level="0" />
                                                    <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>
                                                    ------------------------------------------------------------------------------------------ ------------------
                                                    It always return to FaultEvent.
                                                    can you please tell me where i am wrong? or is there something missing in beta release of Flex3?

                                                    Thanks,
                                                    Vivek
                                                    • 23. Re: Using credentials with a web service -- what our my options?
                                                      JoshBeall Level 1
                                                      Have you used any sniffer tools to see what data is being sent across the wire?
                                                      • 24. Re: Using credentials with a web service -- what our my options?
                                                        lakhanpalv Level 1
                                                        Hi Josh,

                                                        Thanks for replying. I have used <mx:TraceTarget level="0" /> But i couldn't get much in the trace i can send you that trace from console offline if you want.

                                                        Can you please tell me any sniffer tool? I have never used any.
                                                        Thanks,
                                                        Vivek.
                                                        • 25. Re: Using credentials with a web service -- what our my options?
                                                          JoshBeall Level 1
                                                          Well, I'm partial to wireshark, but as Peter rightly pointed out, it's a pretty hefty tool and more than you really need for this job. I'm quite familiar with it since I use it so frequently, but a new user would probably find himself overwhelmed with how to use it.

                                                          I think the trace output will give you what you need; you can PM me the output of that, or PM me and I'll give you my email.

                                                          If you do feel like like running Wireshark, here are a couple tips:

                                                          1) Hit Capture->Options, and make sure your NIC is the interface listed in the dropdown list (it's probably going to default to "default dialup adapter" or some other adapter you don't care about.
                                                          2) In the "Capture filter" textbox, put "tcp port 80" -- this will limit captures to TCP data to or from port 80.
                                                          3) Hit start
                                                          4) Once you've got your capture, you can right click on a TCP packet and hit "Follow TCP stream", and it will give you the content (text) of the stream, so you can actually see what data is being sent and requested. If you filter on the wrong stream, hit the "Clear" button that appears to the right of the "Filter" textbox.

                                                          And I should add:
                                                          0) Keep in mind that Wireshark can only capture data that actually leaves your machine (goes out over your NIC). It can't capture data sent to localhost (127.0.0.1). So if the web service is hosted on your machine, you'll need to go to another machine to run the Flex app.

                                                          -Josh
                                                          • 26. Re: Using credentials with a web service -- what our my options?
                                                            Peter Farland Level 3
                                                            If you have JRun, or another product that embeds JRun such as ColdFusion or LCDS, then there's usually a sniffer.exe in the jrun/bin directory that you can use (note this tool ships with Apache Axis also). A client side proxy that is pretty simple to use with MSIE and is free is "Paros Proxy" (being a client side proxy it can be used to debug HTTPS issues too). There's also Charles which a lot of Flex people use too.

                                                            • 27. Re: Using credentials with a web service -- what our my options?
                                                              lakhanpalv Level 1
                                                              Here is the trace output before the begning of wsdl output:
                                                              direct_http_channel' channel sending message:
                                                              (mx.messaging.messages::HTTPRequestMessage)#0
                                                              body = (Object)#1
                                                              clientId = (null)
                                                              contentType = "application/x-www-form-urlencoded"
                                                              destination = "DefaultHTTP"
                                                              headers = (Object)#2
                                                              httpHeaders = (Object)#3
                                                              messageId = "5709CF78-3BFC-9260-2DF2-0E20B8873D7D"
                                                              method = "GET"
                                                              recordHeaders = false
                                                              timestamp = 0
                                                              timeToLive = 0
                                                              url = " http://192.168.17.26/Wiziq_Latest/Flex/WebService/TestService.asmx?WSDL"
                                                              '8B9BEFCA-5166-42DD-A16C-0E20B867C7AC' producer connected.
                                                              '8B9BEFCA-5166-42DD-A16C-0E20B867C7AC' producer acknowledge of '5709CF78-3BFC-9260-2DF2-0E20B8873D7D'.
                                                              Decoding HTTPService response
                                                              Processing HTTPService response message:
                                                              (mx.messaging.messages::AcknowledgeMessage)#0
                                                              body = "<?xml version="1.0" encoding="utf-8"?>


                                                              And here is the trace output after wsdl output in console:

                                                              clientId = "DirectHTTPChannel0"
                                                              correlationId = "5709CF78-3BFC-9260-2DF2-0E20B8873D7D"
                                                              destination = ""
                                                              headers = (Object)#1
                                                              messageId = "029EF925-E05C-4966-29D9-0E20DFF45052"
                                                              timestamp = 0
                                                              timeToLive = 0
                                                              WSDL loaded
                                                              Creating SOAP Operation for Test
                                                              Invoking SOAP operation Test
                                                              Encoding SOAP request envelope
                                                              Encoding SOAP request body

                                                              Is it ok? or shall i try wireshark or is there any problem with the code? I have included the code in the thread above.

                                                              Thanks & Regards,
                                                              Vivek
                                                              • 28. Re: Using credentials with a web service -- what our my options?
                                                                JoshBeall Level 1
                                                                Peter, correct me if I'm wrong, but shouldn't the "body = " line shows the request and response XML? But it seems to be missing...
                                                                • 29. Re: Using credentials with a web service -- what our my options?
                                                                  Cacademoniaca
                                                                  Hi!
                                                                  I am trying to read the header from a soap request buy I been unable to.... I am using Flex 3 Builder Milestone 3 Beta 2.

                                                                  The SOAP Response is the following..
                                                                  <?xml version="1.0" ?>
                                                                  <soapenv:Envelope xmlns:soapenv=" http://schemas.xmlsoap.org/soap/envelope/"
                                                                  xmlns:xsd=" http://www.w3.org/2001/XMLSchema"
                                                                  xmlns:ns1=" http://testfede.com/"
                                                                  xmlns:ns2=" http://soapinterop.org/xsd">
                                                                  <soapenv:Header>
                                                                  <ns2:ServerVersionInfo>
                                                                  <param1>fede</param1>
                                                                  <param2>fede2</param2>
                                                                  </ns2:ServerVersionInfo>
                                                                  </soapenv:Header>
                                                                  <soapenv:Body>
                                                                  <ns1:sayHiResponse>
                                                                  <return>Holaparam 1</return>
                                                                  </ns1:sayHiResponse>
                                                                  </soapenv:Body>
                                                                  </soapenv:Envelope>

                                                                  I am trying to get the value of the ServerVersionInfo Header.... i tried everything and it always null... even in the debugger the only header is the one that I set going out!

                                                                  Can anyone point me in the right direction?
                                                                  • 30. Re: Using credentials with a web service -- what our my options?
                                                                    Peter Farland Level 3
                                                                    It would, but that first message is an HTTP GET for the WSDL. You'd have to wait for subsequent SOAPMessages to be sent and received.
                                                                    • 31. Re: Using credentials with a web service -- what our my options?
                                                                      lakhanpalv Level 1
                                                                      Pete i didn't get. You meant something for me in the above statement? Please give me some lead i don't see anything in the trace output.

                                                                      Do you have any idea Josh what's up with my code?

                                                                      Any lead will be appreciated.

                                                                      Thanks,
                                                                      Vivek.
                                                                      • 32. Re: Using credentials with a web service -- what our my options?
                                                                        Peter Farland Level 3
                                                                        Hi Vivek, that last reply was for Josh.

                                                                        Looking at your code the problem is that you're trying to access the result or resultHeaders immediately after calling send(). Data services APIs, including WebService, do not work like this in Flex. Calls are made asynchronously - you have to register a result event listener and then wait until your event handler is called.
                                                                        • 33. Re: Using credentials with a web service -- what our my options?
                                                                          lakhanpalv Level 1
                                                                          Hi Pete,

                                                                          Sorry for being so dumb. Today i again tried and got a bit different output in trace:

                                                                          This is after the wsdl output:

                                                                          clientId = "DirectHTTPChannel0"
                                                                          correlationId = "81654544-2E5D-D083-FB38-19F5B93539D8"
                                                                          destination = ""
                                                                          headers = (Object)#1
                                                                          messageId = "BA25F987-75C2-CAB7-AF8C-19F5C3A5FFB2"
                                                                          timestamp = 0
                                                                          timeToLive = 0
                                                                          WSDL loaded
                                                                          Creating SOAP Operation for Test
                                                                          Invoking SOAP operation Test
                                                                          Encoding SOAP request envelope
                                                                          Encoding SOAP request body
                                                                          '1FAB9E14-ECD0-80B4-B4E3-19F5B8F7507F' producer sending message '2DA981A1-F33B-39DA-B6D9-19F5C3F32144'
                                                                          'direct_http_channel' channel sending message:
                                                                          (mx.messaging.messages::SOAPMessage)#0
                                                                          body = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/" xmlns:s=" http://www.w3.org/2001/XMLSchema" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance">
                                                                          <SOAP-ENV:Header>
                                                                          <tns:AuthHeader xmlns:tns=" http://tempuri.org/">
                                                                          <tns:Password>TestPassword</tns:Password>
                                                                          <tns:userName>TestUser</tns:userName>
                                                                          </tns:AuthHeader>
                                                                          </SOAP-ENV:Header>
                                                                          <SOAP-ENV:Body>
                                                                          <tns:Test xmlns:tns=" http://tempuri.org/"/>
                                                                          </SOAP-ENV:Body>
                                                                          </SOAP-ENV:Envelope>"
                                                                          clientId = "DirectHTTPChannel0"
                                                                          contentType = "text/xml; charset=utf-8"
                                                                          destination = "DefaultHTTP"
                                                                          headers = (Object)#1
                                                                          httpHeaders = (Object)#2
                                                                          SOAPAction = "" http://tempuri.org/Test""
                                                                          messageId = "2DA981A1-F33B-39DA-B6D9-19F5C3F32144"
                                                                          method = "POST"
                                                                          recordHeaders = false
                                                                          timestamp = 0
                                                                          timeToLive = 0
                                                                          url = " http://192.168.17.28/TestWS/WebService/TestService.asmx"
                                                                          '1FAB9E14-ECD0-80B4-B4E3-19F5B8F7507F' producer acknowledge of '2DA981A1-F33B-39DA-B6D9-19F5C3F32144'.
                                                                          Decoding SOAP response
                                                                          Encoded SOAP response <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap=" http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=" http://www.w3.org/2001/XMLSchema"><soap:Body><TestResponse xmlns=" http://tempuri.org/"><TestResult>Header Empty</TestResult></TestResponse></soap:Body></soap:Envelope>
                                                                          Decoding SOAP response envelope
                                                                          Decoding SOAP response body
                                                                          Decoded SOAP response into result [21 millis]

                                                                          It says "Header Empty" Can you please tell me where can i be wrong?

                                                                          Thanks,
                                                                          Vivek.

                                                                          • 34. Re: Using credentials with a web service -- what our my options?
                                                                            Peter Farland Level 3
                                                                            Did you try what I mentioned about waiting for the result event to access the header?

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

                                                                            private function sendWS():void
                                                                            {
                                                                            trace("Calling web service");
                                                                            HelloWorldWS.sayHi.addSimpleHeader("fede", " http://soapinterop.org/xsd", "fede","bar");
                                                                            HelloWorldWS.sayHi.send();
                                                                            }

                                                                            private function handleResult(event:ResultEvent):void
                                                                            {
                                                                            trace("Result: " + ObjectUtil.toString(event.result));
                                                                            trace("---Headers: " + HelloWorldWS.sayHi.resultHeaders); //returns null
                                                                            var soapHeader:SOAPHeader;
                                                                            soapHeader = HelloWorldWS.sayHi.getHeader(new QName( new Namespace("ns2", " http://soapinterop.org/xsd"), "ServerVersionInfo") ); //returns null
                                                                            trace("soapHeader: " + soapHeader );
                                                                            }

                                                                            private function handleFault(event:FaultEvent):void
                                                                            {
                                                                            trace(event.fault.toString());
                                                                            }

                                                                            ]]>
                                                                            </mx:Script>

                                                                            <mx:TraceTarget level="0" />
                                                                            <mx:WebService id="HelloWorldWS" wsdl=" http://localhost:18080/WSHeaderTest/TestSOAPHeaderService?WSDL">
                                                                            <mx:operation name="sayHi" result="handleResult(event)" fault="handleFault(event)">
                                                                            <mx:request xmlns="">
                                                                            <s>param 1</s>
                                                                            </mx:request>
                                                                            </mx:operation>
                                                                            </mx:WebService>
                                                                            <mx:Button x="10" y="10" label="Button" click="sendWS();"/>
                                                                            </mx:Application>


                                                                            • 35. Re: Using credentials with a web service -- what our my options?
                                                                              Cacademoniaca Level 1
                                                                              Thanks Pete! It works like that!

                                                                              I haven't realized that I had to wait for the web service call to complete! DAHHH!
                                                                              • 36. Re: Using credentials with a web service -- what our my options?
                                                                                JoshBeall Level 1
                                                                                quote:

                                                                                Originally posted by: lakhanpalv
                                                                                It says "Header Empty" Can you please tell me where can i be wrong?


                                                                                It looks to me like the SOAP header is being sent properly. Perhaps there is a problem with your ASP.NET web service? Can you post the code for your web method "Test" (that's the name of the web method you're calling, right?
                                                                                • 37. Re: Using credentials with a web service -- what our my options?
                                                                                  lakhanpalv Level 1
                                                                                  Hi Josh,

                                                                                  Thanks for looking into it. Here is the code i am using:
                                                                                  Here is the UserCredential class
                                                                                  ===============================================
                                                                                  namespace WIZIQ
                                                                                  {
                                                                                  public class UserCredentials: SoapHeader
                                                                                  {
                                                                                  public string userName;
                                                                                  public string Password;
                                                                                  }
                                                                                  }
                                                                                  =========================================
                                                                                  and here is the testService class which has the Test method i am calling from my Flex app
                                                                                  -----------------------------------------------------------------------------
                                                                                  /// <summary>
                                                                                  /// Summary description for TestService
                                                                                  /// </summary>
                                                                                  [WebService(Namespace = " http://tempuri.org/")
                                                                                  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
                                                                                  public class TestService : System.Web.Services.WebService
                                                                                  {
                                                                                  public WIZIQ.UserCredentials CredentialsHeader;
                                                                                  public TestService()
                                                                                  {
                                                                                  //Uncomment the following line if using designed components
                                                                                  //InitializeComponent();
                                                                                  }
                                                                                  [WebMethod ]
                                                                                  [SoapHeader("CredentialsHeader")]
                                                                                  public string Test()
                                                                                  {
                                                                                  string a = "tyest";
                                                                                  if(CredentialsHeader!=null)
                                                                                  a= CredentialsHeader.userName;
                                                                                  else
                                                                                  a="Header Empty";
                                                                                  return a;
                                                                                  }
                                                                                  }
                                                                                  ------------------------------------------------------------------------------------------ -

                                                                                  Thanks,
                                                                                  Vivek Lakhanpal.
                                                                                  • 38. Using credentials with a web service -- what our my options?
                                                                                    JoshBeall Level 1
                                                                                    Hi Vivek,

                                                                                    In your MXML, try changing this line:

                                                                                    var qName:QName = new QName( " http://soapinterop.org/xsd", "AuthHeader" );

                                                                                    To this:

                                                                                    var qName:QName = new QName( "http//tempuri.org/", "AuthHeader" );

                                                                                    Let me know if that resolves things.

                                                                                    I believe the namespace you use when adding the SOAP header needs to match exactly the namespace on the ASP.NET web service.
                                                                                    • 39. Re: Using credentials with a web service -- what our my options?
                                                                                      lakhanpalv Level 1
                                                                                      Hi Josh,

                                                                                      Thanks for looking into the code.

                                                                                      I tried your suggestion, but it didn't worked.

                                                                                      Is there anything else i can provide you about the code? Pete any idea from your end? Beacuse i am waiting for the result as you suggested.

                                                                                      You can see my code above in the listing.

                                                                                      Thanks,
                                                                                      Vivek.