Skyline Groningen
Toegevoegd op

Add SOAP-headers in Flex

I have read many posts, blogs and pieces of documentation on the illusive subject "soap headers in flex". I have seen many frustrated developers asking for more information on how to add, for example, complex-type SOAP-header information. I also found that I needed to be able to put complex-type headers into my SOAP requests. This for the simple reason that I use wsse security in my webservices. I have found a relative solution that solves my problems. The solution is so relatively simple I could not believe it. What did I need to put into the headers is the following xml: <soapenv:Header> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1"> <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-1375978"> <wsu:Created>2007-07-12T11:05:29.483Z</wsu:Created> <wsu:Expires>2007-07-12T11:10:29.483Z</wsu:Expires> </wsu:Timestamp> <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-11517769"> <wsse:Username>ticket</wsse:Username> <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">TICKET_f1e7cdce-3066-11dc-9782-6160ed7fcc06</wsse:Password> </wsse:UsernameToken> </wsse:Security> </soapenv:Header> This is a basic ws-security implementation for Alfresco. using the must discussed methods, I was not able to get this into my SOAP header just like the code above. What do you need to do is the folowing: 1. define a soap-header element that is the root of your header elements. Like this: var wsseSecurity:QName=new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security"); header=new SOAPHeader(wsseSecurity, {}); This header element will function as your container for all child header elements. 2. put the rest of your header info in the content property of the header variable. like this: header.content= "<wsu:Timestamp xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"Timestamp-1375978\">"+ " <wsu:Created>2007-07-12T10:00:29.483Z</wsu:Created>"+ " <wsu:Expires>2007-07-12T10:59:29.483Z</wsu:Expires>"+ "</wsu:Timestamp>"+ "<wsse:UsernameToken xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"UsernameToken-11517769\">"+ " <wsse:Username>ticket</wsse:Username>"+ " <wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">"+ticketString+"</wsse:Password>"+ "</wsse:UsernameToken>"; 3. and finally attach the header info to your webservice. Like this: alfServ.addHeader(header); And presto. Full header xml will be generated according to my wishes. No need to mess around with the addSimpleHeader method, or more complex forms of the SOAPHeader class. Regards. Marc de Kwant wowww.nl ps. Full example of the function I use to add the above security header into my soap calls. public function headers(ticketString:String):void { // Create QName and SOAPHeader objects. var wsseSecurity:QName=new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security"); header=new SOAPHeader(wsseSecurity, {}); header.content= "<wsu:Timestamp xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"Timestamp-1375978\">"+ " <wsu:Created>2007-07-12T10:00:29.483Z</wsu:Created>"+ " <wsu:Expires>2007-07-12T10:59:29.483Z</wsu:Expires>"+ "</wsu:Timestamp>"+ "<wsse:UsernameToken xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"UsernameToken-11517769\">"+ " <wsse:Username>ticket</wsse:Username>"+ " <wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">"+ticketString+"</wsse:Password>"+ "</wsse:UsernameToken>"; alfServ.addHeader(header); }