2013-04-25 61 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