Hi Dave,
Here is how I did that. I am using Flex Builder 3. I generated code
from WSDL and updated my operation in the BaseXYZ class. It is just 1
line change:
public function hello():AsyncToken
{
// Instead of a new Array, am using the headers from the base class.
var headerArray:Array = headers; // <- my change. It was "new
Array()" here
var out:Object = new Object();
currentOperation =
BaseAddNumbersServiceService.getPort("BaseAddNumbersServicePort").binding.portType.getOperation("hello");
var pc:PendingCall = new PendingCall(out,headerArray);
call(currentOperation,out,pc.token,pc.headers);
return pc.token;
}
Now, set the headers and call the service operation:
// create the service
var ws:AddNumbersService = new AddNumbersService();
// create the headers
var q1:QName=new QName("http://soapinterop.org/xsd", "Header1");
var header1:SOAPHeader = new SOAPHeader(q1,
{string:"bologna",int:"123"});
ws.getWebService().addSimpleHeader("Header1",
"http://soapinterop.org/xsd", "testName", "testValue");
ws.getWebService().addHeader(header1);
// set the result and error handlers
ws.addhelloEventListener(helloResulHandler);
ws.addAddNumbersServiceFaultEventListener(faultHandler);
// call the service
ws.hello_send();
Here is what I see in tcpdump:
Referer: file://localhost/Users/mykola/Documents/Flex Builder
3/SampleClient1/bin-debug/SampleClient1.swf
Content-type: text/xml; charset=utf-8
SOAPAction: "urn:hello"
Content-length: 606
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header>
<ns0:Header1 xmlns:ns0="http://soapinterop.org/xsd">
<ns0:testName>testValue</ns0:testName>
</ns0:Header1>
<ns0:Header1 xmlns:ns0="http://soapinterop.org/xsd">
<ns0:int>123</ns0:int>
<ns0:string>bologna</ns0:string>
</ns0:Header1>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns10:hello xmlns:ns10="http://service.jaxws.mdzyuba.com/"/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Both headers are sent successfully. I hope it will work for you.
- Mykola
Web: http://mdzyuba.googlepages.com
--- In [email protected], "Dave Kong" <[EMAIL PROTECTED]> wrote:
>
> I have used the code generator in Flex and it was fairly smooth. All
> the web methods from the WSDL were corrected generated and call/result
> pairs come in bug-free.
>
> However, I can't figure out how to add some SOAP headers to the
> service so that every call can contain my headers. Does anyone have
> experience with this? I really do like the generator and do not want
> to manually write my service code. (There are too many web methods).
>
> I see a BaseXYZService which extends from AbstractWebService, however,
> calling its addHeader method succeeds, but no headers were included in
> the actual SOAP message. I noticed that the generated code uses
> WSDLOperation and other WSDLxxx objects, which probably does not honor
> AbstractWebService.headers array. (I assume those WSDLxxx are used by
> Apache Axis 2, can anyone point me to the source?)
>
> Any help to add headers to the Flex generated webservice code is
> GREATLY APPRECIATED!
>