2014-09-02 27 views
0

我建立使用KSoap2,Android版本3.3.0Ksoap2 - Android組建的SOAP請求使用多個命名空間定義

我的第二個命名空間SOAP請求消息元素,即使我有 的SoapEnvelope加入它「N1」不加。 setMapping()

<in1 xmlns:n1="http://event.api.company.com">  
    ..... 

我期待此格式的請求消息(正確):

<v:Envelope 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/> 
<v:Body> 
    <updateStatus xmlns="http://service.api.company.com" 
     id="o0" c:root="1"> 
     <in0>1604509</in0> 
     <in1 xmlns:n1="http://event.api.company.com"> 
      <n1:actionDate>2014-09-02T05:18:20.156+0000</n1:actionDate> 
      <n1:ActionTypeDTO>      
       <n1:id>1</n1:id> 
       <n1:name>Other</n1:name> 
       <n1:description>Enter the description of the action taken.</n1:description>      
      </n1:ActionTypeDTO> 
      <n1:description>notes1</n1:description> 
      <n1:name>system</n1:name> 
     </in1> 
     <in2>NEW</in2> 
    </updateStatus> 
</v:Body> 

但我得到這個(錯誤的)KSOAP建立消息後:

<v:Envelope 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/> 
<v:Body> 
    <updateStatus xmlns="http://service.api.company.com" 
     id="o0" c:root="1"> 
     <in0>1604509</in0> 
     <in1> 
      <actionDate>2014-09-02T05:18:20.156+0000</actionDate> 
      <ActionTypeDTO>      
       <id>1</id> 
       <name>Other</name> 
       <description>Enter the description of the action taken.</description>      
      </ActionTypeDTO> 
      <description>notes1</description> 
      <name>system</name> 
     </in1> 
     <in2>NEW</in2> 
    </updateStatus> 
</v:Body> 

這是使用KSOAP2,Android的API我的功能:

public void updateStatus(long in0, ActionDTO in1){ 

    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    soapEnvelope.implicitTypes = true; 
    soapEnvelope.dotNet = true; 

    SoapObject soapReq = new SoapObject("http://service.api.company.com","updateEventStatus"); 

    soapEnvelope.addMapping("http://event.api.company.com","in1",new ActionDTO().getClass()); 

    soapReq.addProperty("in0",in0); 
    soapReq.addProperty("in1",in1); 
    soapEnvelope.setOutputSoapObject(soapReq); 


    HttpTransportSE httpTransport = new HttpTransportSE(url,timeOut); 


    httpTransport.call("http://service.api.company.com/updateEventStatus", 
         soapEnvelope); 
    } 

請參閱以下內容未添加到肥皂請求中:

<in1 xmlns:n1="http://event.api.company.com">  
    <n1:actionDate>2014-09-02T05:18:20.156+0000</n1:actionDate> 
    ..... 
    ....... 
    ..... 

任何人可以幫助我什麼,我做錯了... soapEnvelope.addMapping()函數 似乎無法正常工作。或者我錯過了一些設置或標誌告訴KSOAP?

我刪除了一些代碼,使其乾淨瞭解,對不起那個.... 提前感謝您的幫助...

+0

如果您顯示wsdl文件,會更容易。但你可以嘗試http://easywsdl.com生成器。它支持肥皂請求/響應中的許多命名空間。不幸的是,它不是免費的。 – robocik 2014-09-11 09:13:03

+0

嗨,謝謝。我會嘗試。但不幸的是我不能發佈我的wsdl文件。 – skstar 2014-09-16 10:53:16

回答

0

一些如何想出解決問題的了。

如果有人使用'Wsdl2Code'來生成Java代碼,那麼它可能會很有用。

(!WSDL2CODE.com引擎將生成的類和方法,用於連接SOAP服務從Android和iPhone)

在Wsdl2code產生的DTO類改變如下:

public void getPropertyInfo(int index, 
     @SuppressWarnings("rawtypes") Hashtable arg1, PropertyInfo info) { 

    switch (index) { 
    case 0: 
     **info.namespace = "http://event.api.company.com";** 
     info.type = PropertyInfo.STRING_CLASS; 
     info.name = "id"; 
     break; 
    case 1: 
     **info.namespace = "http://event.api.company.com";** 
     info.type = PropertyInfo.STRING_CLASS; 
     info.name = "name"; 
     break;  
    } 
} 

那麼就會產生正如我在問題(正確)中提到的SOAP請求。

相關問題