3 Replies Latest reply on Dec 12, 2006 6:41 AM by Mark.P.

    Web Services headers

    Mark.P. Level 1
      For some reason I'm having a hard time figuring out how to add a header in Flex. Can anyone lend a hand that has done it? I went over the built-in help but it isn't making a lot of sence to me. Here's what I used in Flash 7, maybe this will help someone help me convert what I need -


      // START WEB SERVICE CALL \\
      function addSOAPHeaderFix() {
      if (mx.services.PendingCall.prototype.__encodeSOAPHeader__ != null) {
      return;
      }
      mx.services.PendingCall.prototype.__encodeSOAPHeader__ = mx.services.PendingCall.prototype.encodeSOAPHeader;
      mx.services.PendingCall.prototype.encodeSOAPHeader = function() {
      var theService = this.myCall.wsdlOperation.wsdl.serviceProxy.service;
      // here is how to do headers that apply to all calls
      for (var i = 0; i < theService.headersForAllCalls.length; i++) {
      this.addHeader(theService.headersForAllCalls );
      }
      // here is how to do headers that apply to only one specific call
      for (var j = 0; j < theService.headersForOneCall.length; j++) {
      this.addHeader(theService.headersForOneCall[j]);
      }
      theService.headersForOneCall = null;
      this.__encodeSOAPHeader__();
      };
      }
      addSOAPHeaderFix();
      var service:mx.services.WebService;
      service = new mx.services.WebService(" http://radar.net/RadarXML.asmx?WSDL");
      var header1 = new XML('<AuthHeader xmlns=" http://tempuri.org/"><UserName>admin</UserName><Password>admin</Password></AuthHeader>');
      service.headersForAllCalls = new Array();
      service.headersForAllCalls.push(header1);
      var myObj:mx.services.PendingCall = service.PullXML();
      //
      // IF no fault has occured then XML is received \\
      myObj.onResult = function(result) {
      // change results to Flash XML \\
      _global.theResults = new XML(result);
      // strip out any white space \\
      theResults.firstChild.stripWhite();
      //load necessary script \\
      loadAndSeperate();
      };
      // IF a fault occures get XML \\
      myObj.onFault = function(result) {
      _global.theResults = new XML();
      theResults.ignoreWhite = true;
      theResults.onLoad = function(success) {
      loadAndSeperate();
      };
      // load the XML into the XML object
      theResults.load("PublishXML/PublishedProjects.xml");
      };
      // END WEB SERVICE CALL \\