Apache flex 如何添加一个“;“平坦”;flex web服务调用的消息头?
我有一个连接到web服务的flex客户端,它需要添加一个身份验证令牌作为标题,名为“Identity”。预期消息的一个示例是:Apache flex 如何添加一个“;“平坦”;flex web服务调用的消息头?,apache-flex,web-services,Apache Flex,Web Services,我有一个连接到web服务的flex客户端,它需要添加一个身份验证令牌作为标题,名为“Identity”。预期消息的一个示例是: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header> <Identity xmlns="ns">2188dcbe-0325-4c1e-9a77-19110e0ea99f</Identity> <To
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Identity xmlns="ns">2188dcbe-0325-4c1e-9a77-19110e0ea99f</Identity>
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">https://localhost:8001/MyService</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">ns/MyService/MyOperation</Action>
</s:Header>
<s:Body>
...
</s:Body>
</s:Envelope>
2188dcbe-0325-4c1e-9a77-19110e0ea99f
https://localhost:8001/MyService
似乎建议您可以使用原始XML,但我一直无法使其正常工作
提前感谢您的指点 有几种方法可以做到这一点。我个人更喜欢重写本机SOAPEncoder类,该类允许您在发送前访问实际的soap信封。这使您能够拥有更多的控制并添加诸如ws-addressing和自定义身份验证头之类的内容
public class myEncoder
extends SOAPEncoder
{
private const WSSE_NS:Namespace = new Namespace("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsswssecurity-secext-1.0.xsd");
//--------------------------------------------------------------------------
//
// Constructor
//
//--------------------------------------------------------------------------
public function wsseEncoder()
{
super();
}
//--------------------------------------------------------------------------
//
// Methods
//
//--------------------------------------------------------------------------
/**
* <p> override super classes method and recieve raw soap message to manpulate soap envelope
* </p>
*/
public override function encodeRequest(args:* = null, headers:Array = null):XML
{
//get soap envelope from super class
var SOAPEnvelope:XML = super.encodeRequest(args, headers);
//create a header in xml and append it at as a child
securityHeaderXml = <Security/>;
securityHeaderXml.setNamespace(WSSE_NS);
securityHeaderXml.@[mustUnderstand] = 1;
//set deafult ws-security namespace - filters to all child nodes
securityHeaderXml.setNamespace(WSSE_NS);
var id:XML = <Identity/>;
id.appendChild('value here');
SOAPEnvelope.prependChild(id);
SOAPEnvelope.prependChild(headerXml);
return SOAPEnvelope;
}
}
}
公共类myEncoder
扩展SOAPEncoder
{
private const WSSE_NS:Namespace=新名称空间(“WSSE”,”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsswssecurity-secext-1.0.xsd");
//--------------------------------------------------------------------------
//
//建造师
//
//--------------------------------------------------------------------------
公共函数wsseEncoder()
{
超级();
}
//--------------------------------------------------------------------------
//
//方法
//
//--------------------------------------------------------------------------
/**
*重写超类方法并接收原始soap消息以操纵soap信封
*
*/
公共重写函数encodeRequest(args:*=null,headers:Array=null):XML
{
//从超级类获取soap信封
var SOAPEnvelope:XML=super.encodeRequest(参数、头);
//在xml中创建一个标头,并将其作为子项附加到
securityHeaderXml=;
setNamespace(WSSE_NS);
securityHeaderXml@[mustUnderstand]=1;
//将deafult ws-security命名空间筛选器设置为所有子节点
setNamespace(WSSE_NS);
变量id:XML=;
id.appendChild('value here');
SOAPEnvelope.prependChild(id);
SOAPEnvelope.prependChild(headerXml);
退回信封;
}
}
}
然后,您需要做的就是将默认编码器更改为此编码器,如果您使用的generate web服务类转到serviceBase并查找方法“Call”,然后将此行更改为此编码器
var enc:SOAPEncoder=new myEncoder()//而不是此->新建SOAPEncoder()
如果没有,则类似于myService.encoder=new myEncoder()
就这么简单
显然,重写编码器类可以为您提供更多的控制。您还可以对SOAPDecoder类执行相同的操作,以便在soap信封反序列化之前捕获它
希望这有帮助
乔恩
public class myEncoder
extends SOAPEncoder
{
private const WSSE_NS:Namespace = new Namespace("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsswssecurity-secext-1.0.xsd");
//--------------------------------------------------------------------------
//
// Constructor
//
//--------------------------------------------------------------------------
public function wsseEncoder()
{
super();
}
//--------------------------------------------------------------------------
//
// Methods
//
//--------------------------------------------------------------------------
/**
* <p> override super classes method and recieve raw soap message to manpulate soap envelope
* </p>
*/
public override function encodeRequest(args:* = null, headers:Array = null):XML
{
//get soap envelope from super class
var SOAPEnvelope:XML = super.encodeRequest(args, headers);
//create a header in xml and append it at as a child
securityHeaderXml = <Security/>;
securityHeaderXml.setNamespace(WSSE_NS);
securityHeaderXml.@[mustUnderstand] = 1;
//set deafult ws-security namespace - filters to all child nodes
securityHeaderXml.setNamespace(WSSE_NS);
var id:XML = <Identity/>;
id.appendChild('value here');
SOAPEnvelope.prependChild(id);
SOAPEnvelope.prependChild(headerXml);
return SOAPEnvelope;
}
}
}