2013-10-09 129 views
1

我得到了我的生成代碼的小問題:KSOAP2如何更改前綴

在這裏,我需要有XML結構:

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?> 
<soapenv:Envelope xmlns:v1="http://openclinica.org/ws/study/v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="soapenc" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<soapenv:Header> 
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
<wsse:UsernameToken wsu:Id="UsernameToken-27777511" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
<wsse:Username>xxxx</wsse:Username> 
<wsse:Password type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxxxxxx</wsse:Password> 
</wsse:UsernameToken> 
</wsse:Security> 
</soapenv:Header> 
<soapenv:Body> 
<v1:listAllRequest/> 
</soapenv:Body> 
</soapenv:Envelope> 

和here's我的代碼,我已經做了:

declarePrefix("v1", NAMESPACE); 
getBody().addTextNode(null, METHOD_NAME, "?"); 
XMLParentNode security = new XMLParentNodeImpl(HEADER_NAMESPACE, "Security"); 
security.addAttribute(HEADER_NAMESPACE,"mustUnderstand", "1"); 
XMLParentNode usernameToken = new XMLParentNodeImpl(UNT_NAMESPACE, "UsernameToken"); 
usernameToken.addTextNode(null, "wsse:Username", "root"); 
usernameToken.addTextNode(PASSTYPE, "wsse:Password", Constants.OC_PASSWORD); 
security.addElement(usernameToken); 
getHeader().addElement(security); 

,但輸出的樣子:

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?> 
<soapenv:Envelope xmlns:v1="http://openclinica.org/ws/study/v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<soapenv:Header> 
<n0:Security n0:mustUnderstand="1" xmlns:n0="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
<n1:UsernameToken xmlns:n1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
<wsse:Username>xxxx</wsse:Username> 
<n2:wsse:Password xmlns:n2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxxxxxx</n2:wsse:Password> 
</n1:UsernameToken> 
</n0:Security> 
</soapenv:Header> 
<soapenv:Body> 
<listAllRequest>?</listAllRequest> 
</soapenv:Body> 
</soapenv:Envelope> 

你看,我有一些麻煩與線

<n0:Security.... 
<n1:UsernameToken... 
<n2:wsse:Password... 

我怎樣才能改變N0,N1等...不只是在像N0標籤的線specialy的初學者:mustUnderstand屬性=「1」

我試着聲明前綴等,但沒有改變這個對象。

誰能告訴用什麼方法,我可以改變這個事情 非常感謝幫助

基督教

回答

0

所有intrestet用戶,我解決了這樣的說法:

declarePrefix("v1", NAMESPACE); 
     declarePrefix("soapenc", "soapenc"); 
     getBody().addTextNode(null, METHOD_NAME, "?"); 
     XMLParentNode security = new XMLParentNodeImpl(null, "wsse:Security"); 
     security.declarePrefix("wsse", HEADER_NAMESPACE); 
     security.addAttribute(HEADER_NAMESPACE,"mustUnderstand", "1"); 
     XMLParentNode usernameToken = new XMLParentNodeImpl(null, "wsse:UsernameToken"); 
     usernameToken.declarePrefix("wsu", UNT_NAMESPACE); 
     usernameToken.addAttribute(null, "wsu:Id", "UsernameToken-27777511"); 
     usernameToken.addTextNode(null, "wsse:Username", Constants.OC_Username); 
     usernameToken.addTextNode(null, "wsse:Password", Constants.OC_PASSWORD); 
     security.addElement(usernameToken); 
     getHeader().addElement(security); 

結果不是100%與我的外發代碼類似,但請求正在工作:)