java - kSoap2 发送集合

标签 java .net android android-ksoap2

我有android应用程序,它将一些数据发送到.net web服务(不是wcf,简单的web服务) 在android应用程序上我有一个类,它实现了KvmSerialized接口(interface)

public class OrderDTO extends BaseSoapObject
{
    public int ID;
    public Date OrderDate;
    public UserDTO Owner; 
    public Vector<OrderItemDTO> Products;

    @Override
public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info)
{
    switch(index)
    {
        case 0:
            info.type = PropertyInfo.INTEGER_CLASS;
            info.name = "ID";
            break;

        case 1:
            info.type = MarshalDate.DATE_CLASS;
            info.name = "OrderDate";
            break;

        case 2:
            info.type = UserDTO.class;
            info.name = "Owner";
            break;

        case 3:
            info.type = PropertyInfo.VECTOR_CLASS;
            info.name = "Products";
            break;

        default:
            break;
    }       
}
}

在服务器端我有类(class)

public class OrderDTO
{
    public virtual int ID { get; set; }
    public virtual UserDTO Owner { get; set; }
    public virtual DateTime OrderDate { get; set; }
    public virtual OrderItemDTO[] Products { get; set; }

    public OrderDTO()
    {    
    }
}

以及网络服务方法

[Web方法]

public void SaveOrder(OrderDTO order)
{
    try
    {
        // do somthing
    }
    catch (Exception e)
    {

    }
    finally
    {
    }

}

我已成功从 android 调用此方法,字段 Owner 和 OrderDate 已正确填写,但 Products 字段为空(不是 null,只是空)

我尝试使用 Array、ArrayList 和 Vector - 没有变化

当我看到请求转储并发现唯一不同的是(集合项目的标签名称:

<Products i:type="c:Array" c:arrayType="d:anyType[1]">
    <item i:type="n0:OrderItemDTO">
       <ID i:type="d:int">0</ID>
       <AssignedCode i:type="d:string">0001</AssignedCode>
       <Count i:type="d:int">5</Count>
    </item>
</Products>

在我的 wsdl 中:

<Products>
    <OrderItemDTO>
        <ID>int</ID>
        <Count>int</Count>
        <AssignedCode>string</AssignedCode>
    </OrderItemDTO>
    <OrderItemDTO>
        <ID>int</ID>
        <Count>int</Count>
        <AssignedCode>string</AssignedCode>
    </OrderItemDTO>
</Products>

以及我与服务交互的 Android 代码:

OrderDTO dto = new OrderDTO(order);
SoapObject request = new SoapObject(Namespace, SaveOrderMethod);

PropertyInfo pi = new PropertyInfo();
pi.setName("order");
pi.setValue(dto);
pi.setType(dto.getClass());
request.addProperty(pi); 

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
envelope.dotNet = true;
envelope.setOutputSoapObject(request);

envelope.addMapping(Namespace, "OrderItemDTO", new OrderItemDTO().getClass());
envelope.addMapping(Namespace, "UserDTO", new UserDTO().getClass());
envelope.addMapping(Namespace, "OrderDTO", new OrderDTO().getClass());

Marshal dateMarshal = new MarshalDate();
dateMarshal.register(envelope);

HttpTransportSE androidHttpTransport = new HttpTransportSE(Url);
androidHttpTransport.debug = true;

try
{
    androidHttpTransport.call(SaveOrderSoapAction, envelope);
} 
catch (Exception e) 
{
    Log.e(Tag, e.getMessage());
}

最佳答案

我找到了答案,我需要向 OrderDTO.getPropertyInfo 方法添加一些代码 PropertyInfo elementInfo = new PropertyInfo(); elementInfo.name = "OrderItemDTO"; elementInfo.type = new OrderItemDTO().getClass(); info.elementType = elementInfo;

关于java - kSoap2 发送集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5727814/

相关文章:

java - 将 watch 置于断点时,Java 调试器显示盒装整数而不是原始整数

.net - 在分析(采样)应用程序时忽略 GC

android - 不管怎样从时间上得到上午/下午?

java - 如何从另一个类填充我的数组?(Java)

java - 单元测试 ArrayMap 抛出异常放入 android.util.ArrayMap 中的方法未被模拟

javascript - .net ReportViewer javascript 错误

android - 为 ListView 禁用滚动并为整个布局启用

android - GLSL ES 3.0 - 在顶点和 fragment 着色器中统一,以及最大顶点/fragment 统一向量

java - 如何以独特的方式分配变量以求减法中的补数

.net - 如何从服务调用主 UI 线程