0

我正在尝试将 2 个字符串从我的 php nusoap 服务器传回我的 ksoap2 客户端,但 ksoap2 没有将来自 nusoap 的响应拆分为不同的属性。

这是我在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 的肥皂响应(是的,我知道这是一个错误。主机提供商有问题)

<?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());
4

1 回答 1

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());
于 2012-08-04T02:54:34.247 回答