2013-04-25 98 views
0

雖然發送SOAP請求,我需要這樣的創建頭部分:Android的SOAP信封與安全頭

enter image description here

我在這裏看到了一個類似的問題: create soap envelope with security header in android using ksoap2

我刪除了部分這我不需要在代碼部分。

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 


    Element[] header = new Element[1]; 
    header[0] = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security"); 

    Element usernametoken = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "UsernameToken"); 
    header[0].addChild(Node.ELEMENT,usernametoken); 

    Element username = new Element().createElement(null, "n0:Username"); 
    username.addChild(Node.TEXT,"User"); 
    usernametoken.addChild(Node.ELEMENT,username); 

    Element pass = new Element().createElement(null,"n0:Password"); 
    pass.setAttribute(null, "Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"); 
    pass.addChild(Node.TEXT, "pass"); 

    usernametoken.addChild(Node.ELEMENT, pass); 


    // add header to envelope 
    envelope.headerOut = header; 

我需要添加什麼東西嗎?謝謝!!

回答

0

你面對的是什麼問題?有什麼錯誤?

您已賦予鏈接由我發佈。這是完美的運行沒有任何錯誤。

+0

我解決了它,我只需要刪除一些未使用的元素屬性。所以是的,它沒有任何錯誤。感謝您的關注。 – Rnklnc 2013-04-26 07:22:37