2012-07-24 64 views
0

我想從我的PHP nusoap服務器傳回2個字符串到我的ksoap2客戶端,但ksoap2並沒有將nusoap的響應分成不同的屬性。PHP nusoap到Java複雜變量

這是我在java中製作複雜對象的類。

import java.util.Hashtable; 


import org.ksoap2.serialization.KvmSerializable; 
import org.ksoap2.serialization.PropertyInfo; 


public class ArrayOfStrings implements KvmSerializable { 

    public String Status; 
    public String Data; 

    public ArrayOfStrings(){} 

    public ArrayOfStrings(String status, String data) { 
     Status=status; 
     Data=data; 
    } 

    @Override 
    public Object getProperty(int arg0) { 
     // TODO Auto-generated method stub 
     switch (arg0) { 
     case 0: 
      return Status; 
     case 1: 
      return Data; 
     } 
     return null; 
    } 

    @Override 
    public int getPropertyCount() { 
     // TODO Auto-generated method stub 
     return 2; 
    } 

    @Override 
    public void getPropertyInfo(int index, Hashtable hashtbl, PropertyInfo pi) { 
     // TODO Auto-generated method stub 
     switch (index) { 
     case 0: 
     pi.type=PropertyInfo.STRING_CLASS; 
     pi.name="Status"; 
     break; 
     case 1: 
     pi.type=PropertyInfo.STRING_CLASS; 
     pi.name="Data"; 
     default: break; 
     } 
    } 

    @Override 
    public void setProperty(int index, Object o) { 
     // TODO Auto-generated method stub 
     switch (index) { 
     case 0: 
      Status = o.toString(); 
      break; 
     case 1: 
      Data = o.toString(); 
      break; 
     default: break; 
     } 
    } 

} 

下面是在PHP nusoap中添加complexType的代碼。

$server->wsdl->addComplexType("ArrayOfStrings", 
     "complexType", 
     "struct", 
     "", 
     "SOAP-ENC:Array", 
     array('Status'=> array('name' => 'Status', 'type' => 'xsd:string'), 
       'Data'=> array('name' => 'Data', 'type' => 'xsd:string')) 
); 

$server->register("appswitch",  
     array( "app" => "xsd:string", 
       "content" => "xsd:string"), 
     array("ArrayOfStrings" => "tns:ArrayOfStrings"), 
     "urn:webservices", 
     "urn:Submit#appswitch", 
     "rpc", 
     "encoded", 
     "G4Apps Webservices Gateway"); 

任何想法?

編輯:下面是PHP SOAP響應(是的,我知道這是一個錯誤的主機提供商是有問題的。)

<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:webservices"> 
<SOAP-ENV:Body> 
    <ns1:appswitchResponse xmlns:ns1="http://secure.g4apps.com/webservices/"> 
     <return xsi:type="tns:ArrayOfStrings"> 
      <Status xsi:type="xsd:string">error</Status> 
      <Data xsi:type="xsd:string"> 
       Soap Service failed to insert data: 
       INSERT INTO phonelog (AppID,TransactionType, TransactionSubType, VirtualTagNo, SmartphoneID, TimeStampEvent, TimeStampLog, GPSLat, GPSLong, TruckID, TruckOdometer, TruckEngType) 
       VALUES (&apos;A1&apos;,&apos;M1&apos;,&apos;E1&apos;,&apos;AT333AT333&apos;,&apos;9055627513&apos;,&apos;2012-02-02 02:02:02&apos;,&apos;2012-02-02 02:02:02&apos;,&apos;-454545.343434&apos;,&apos;434343.232323&apos;,&apos;A334A334A334A443X&apos;,&apos;1000000&apos;,&apos;3434&apos;) 
      </Data> 
     </return> 
    </ns1:appswitchResponse> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

我想我就找錯了對象。我根本不需要ArrayOfStrings類來將值從我的響應中提取出來。

繼承人我的代碼片段。

 SoapObject ks= (SoapObject)env.bodyIn; 
     SoapObject inner = (SoapObject)ks.getProperty("return"); 
     String Status = inner.getProperty("Status").toString(); 
     String Data = inner.getProperty("Data").toString(); 


     //System.out.println(ht.requestDump); 
     //System.out.println(ht.responseDump); 

     System.out.println(Status.trim()); 
     System.out.println(Data.trim()); 

回答

0

我想我是在吠叫錯誤的樹。我根本不需要ArrayOfStrings類來將值從我的響應中提取出來。

繼承人我的代碼片段。

SoapObject ks= (SoapObject)env.bodyIn; 
    SoapObject inner = (SoapObject)ks.getProperty("return"); 
    String Status = inner.getProperty("Status").toString(); 
    String Data = inner.getProperty("Data").toString(); 


    //System.out.println(ht.requestDump); 
    //System.out.println(ht.responseDump); 

    System.out.println(Status.trim()); 
    System.out.println(Data.trim());