2009-08-07 3 views
0

나는 "Identity"라는 헤더로 추가 된 인증 토큰을 필요로하는 웹 서비스에 연결하는 플렉스 클라이언트를 가지고 있습니다. 예상되는 메시지의 예는 다음과 같습니다.플렉스 웹 서비스 호출에 "플랫"메시지 헤더를 추가하는 방법은 무엇입니까?

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

플렉스에서 어떻게 이런 종류의 헤더를 추가합니까? 나는 .addHeader()와 .addSimpleHeader 모두를 사용하여 시도했지만,이 둘은 같은 헤더 요소에 하위 요소를 추가하는 것 : 플렉스가이 일을하기 때문에, 나는이 가능해야한다 알고

<Identity xmlns="ns"> 
    <Value>34234234-234-234-23-234324</Value> 
</Identity> 

"받는 사람"및 "활동"헤더. addHeader에 대한 설명서에서 원시 XML을 제공 할 수 있다고 제안하는 것 같지만 작동시키지 못했습니다.

미리 알려 주셔서 감사합니다!

답변

1

두 가지 방법이 있습니다. 개인적으로 SOAPEncoder 클래스를 재정의하는 것을 선호합니다. SOAPEncoder 클래스는 전송되기 전에 실제 비누 봉투에 대한 액세스 권한을 제공합니다. 이렇게하면 더 많은 제어가 가능하고 ws-addressing 및 custom authenication 헤더와 같은 항목을 추가 할 수 있습니다.

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); 
     [email protected][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; 
    } 


    } 
} 

그런 다음 당신이해야 할 모든 당신의 웹 서비스 클래스를 생성 사용하는 경우,이 일에 기본 인코더를 변경 serviceBase로 이동하는 방법 '호출'이

이 줄을 변경 찾아이다

var enc : SOAPEncoder = new myEncoder(); // 이것 대신에 -> 새로운 SOAPEncoder();

그렇지 않은 경우 다음과 같습니다. myService.encoder = new myEncoder();

간단합니다.

분명히 인코더 클래스를 재정 의하여 제어력을 향상시킬 수 있습니다. 또한 SOAPDecoder 클래스에서 동일한 작업을 수행하여 직렬화가 해제되기 전에 비누 봉투를 잡을 수 있습니다.

희망이

을하는 데 도움이
관련 문제