无法使用kso​​ap2在Android中序列化错误

时间:2014-07-25 08:55:43

标签: android api magento ksoap2

我有一个magento soap v2 api webservice。我可以使用kso​​ap2从android进行通信。我尝试的xml和编码如下所示。

------------ XML Api -----------

<operation name="catalogProductCreate">
<documentation>Create new product and return product id</documentation>
<input message="typens:catalogProductCreateRequest"/>
<output message="typens:catalogProductCreateResponse"/></operation>


<message name="catalogProductCreateRequest">
<part name="sessionId" type="xsd:string"/>
<part name="type" type="xsd:string"/>
<part name="set" type="xsd:string"/>
<part name="sku" type="xsd:string"/>
<part name="productData" type="typens:catalogProductCreateEntity"/>
<part name="storeView" type="xsd:string"/>
</message>


<complexType name="catalogProductCreateEntity">
<all>
<element name="categories" type="typens:ArrayOfString" minOccurs="0"/>
<element name="websites" type="typens:ArrayOfString" minOccurs="0"/>
<element name="file" type="typens:catalogProductImageFileEntity" minOccurs="0"/
<element name="name" type="xsd:string" minOccurs="0"/>
<element name="description" type="xsd:string" minOccurs="0"/>
<element name="short_description" type="xsd:string" minOccurs="0"/>
<element name="weight" type="xsd:string" minOccurs="0"/>
<element name="status" type="xsd:string" minOccurs="0"/>
</all>
</complexType>

<complexType name="catalogProductImageFileEntity">
<all>
<element name="content" type="xsd:string"/>
<element name="mime" type="xsd:string"/>
<element name="name" type="xsd:string" minOccurs="0"/>
</all>
</complexType>

------------ MainClass ---------

request = new SoapObject(NAMESPACE,"catalogProductCreate");

        request.addProperty("sessionId", sessionId);

        request.addProperty("type", "simple");
        request.addProperty("set", "4");
        request.addProperty("sku", sku.toString());

        //-----use Kvm Serializable class to serialize the key value data-------

        CreateProductKVMserialize createproductkvm = new CreateProductKVMserialize();

        createproductkvm.Name = name;
        createproductkvm.Description = description;
        createproductkvm.ShortDescription = shortdescription;

        createproductkvm.Weight = weight;
        createproductkvm.Status = "1";
        createproductkvm.Price = price;

        PropertyInfo pi = new PropertyInfo();
        pi.setName("productData");
        pi.setValue(createproductkvm);
        pi.setType(createproductkvm.getClass());
        request.addProperty(pi);

        env.setOutputSoapObject(request);

        env.addMapping(NAMESPACE, "productData",new CreateProductKVMserialize().getClass());

        androidHttpTransport.call("", env);
        Object product_create = env.getResponse();
        Log.d("mainactivity "," "+product_create.toString());

------------- CreateProductKVMserialize class ----------

public class CreateProductKVMserialize implements KvmSerializable{

public String[] Categories; // this array i cant send it shows cannot serialize error
public String Name;
public String Description;
public String ShortDescription;
public String Weight;
public String Status;
public String Price;

public CreateProductKVMserialize(){}

public CreateProductKVMserialize(String[] categories,String name, String description, String shortdescription, String weight,String status,String price) {

    Categories = categories;
    Name = name;
    Description = description;
    ShortDescription = shortdescription;
    Weight = weight;
    Status= status;
    Price = price;
}

@Override
public Object getProperty(int arg0) {
    // TODO Auto-generated method stub
     switch(arg0)
        {
        case 0:
            return Categories;
        case 1:
            return Name;
        case 2:
            return Description;
        case 3:
            return ShortDescription;
        case 4:
            return Weight;  
        case 5:
            return Status;  
        case 6:
            return  Price ; 

        }

        return null;

}

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

@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
    // TODO Auto-generated method stub

     switch(index)
        {
        case 0:
            info.type = PropertyInfo.VECTOR_CLASS;
            info.name = "categories";
            break;
        case 1:
            info.type = PropertyInfo.STRING_CLASS;
            info.name = "name";
            break;
        case 2:
            info.type = PropertyInfo.STRING_CLASS;
            info.name = "description";
            break;
        case 3:
             info.type = PropertyInfo.STRING_CLASS;
             info.name = "short_description";
            break;
        case 4:
             info.type = PropertyInfo.STRING_CLASS;
             info.name = "weight";
            break;
        case 5:
             info.type = PropertyInfo.STRING_CLASS;
             info.name = "status";
            break;
        case 6:
             info.type = PropertyInfo.STRING_CLASS;
             info.name = "price";
            break;

        default:break;
        }
}

@Override
public void setProperty(int index, Object value) {
    // TODO Auto-generated method stub

    switch(index)
    {
    case 0:
        Categories = (String[])value;
        break;
    case 1:
        Name = value.toString();
        break;
    case 2:
        Description = value.toString();
        break;
    case 3:
        ShortDescription = value.toString();
        break;
    case 4:
        Weight = value.toString();
        break;
    case 5:
        Status = value.toString();
        break;
    case 6:
        Price = value.toString();
        break;

    default:
        break;
    }
 }

}

但问题是我无法发送复杂类型的数据(例如:Array)和  直到“catalogProductCreateEntity”只有我可以通信,如果我发送数组数据它显示错误“无法序列化..”。如何以“typens:ArrayOfString”的形式发送数据,以及如何与“catalogProductImageFileEntity”(“catalogProductCreateEntity”中的名称类型)进行通信。

0 个答案:

没有答案