2017-04-11 187 views
2

如何使用kso​​ap向肥皂添加前綴標記? 我想補充領域:xmlns:CNX = 「http://db.hutt.com」向soap請求添加xml前綴

<v:Envelope xmlns:cnx="http://db.hutt.com" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"> 
     <v:Header> 
      <authentication xmlns:n0="http://db.hutt.com"> 
       <userName>tutt</userName> 
       <password>[email protected]</password> 
      </authentication> 
     </v:Header> 
     <v:Body> 
      <cnx:get_tt xmlns=""> 
       <ttid>1</ttid> 
      </cnx:get_tt> 
     </v:Body> 
    </v:Envelope> 
+0

編輯完您的請求後,它似乎是等同的。你想改變什麼? – KarelHusa

+1

ttid元素可能不屬於名稱空間http://sdm.hott.com。您可以使用以下方法添加ttid元素:public SoapObject addProperty(String namespace,String name,Object value)並將該名稱空間設置爲空字符串。 – KarelHusa

+0

@KarelHusa我編輯了這個問題。我可以看到標題不應該有一些標籤,而身體請求應該有標籤。 – kinkajou

回答

0

因此,它並不重要的永遠標記,你可以舉例:V:信封或soapenv:信封。 soapserver會自動解析它。另外,要在xml信封中添加前綴,您需要擴展SoapSerializationEnvelope

import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.xmlpull.v1.XmlSerializer; 

import java.io.IOException; 

/** 
* Created by suamatya on 4/11/2017. 
*/ 

public class CustomSoapSerializationEnvelope extends SoapSerializationEnvelope { 

    CustomSoapSerializationEnvelope(int version){ 
     super(version); 
    } 

    @Override 
    public void write(XmlSerializer writer) throws IOException { 
     writer.setPrefix("i", xsi); 
     writer.setPrefix("d", xsd); 
     writer.setPrefix("c", enc); 
     writer.setPrefix("v", env); 
     writer.setPrefix("db","http://db.hott.com"); 
     writer.startTag(env, "Envelope"); 
     writer.startTag(env, "Header"); 
     writeHeader(writer); 
     writer.endTag(env, "Header"); 
     writer.startTag(env, "Body"); 
     writeBody(writer); 
     writer.endTag(env, "Body"); 
     writer.endTag(env, "Envelope"); 
    } 
}