1

私はAndroidアプリケーションで.net Webサービス(wcfではなく、単純なWebサービス)にデータを送信するAndroidアプリケーションを持っていますKvmSerializableインターフェースを実装するクラスを持っています

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;
    }       
}
}

サーバー側で私はクラスを持っています

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
    {
    }

}

私はアンドロイドからこのメソッドを呼び出すことに成功しました.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());
}
4

1 に答える 1

0

OrderDTO.getPropertyInfo メソッド PropertyInfo elementInfo = new PropertyInfo(); にいくつかのコードを追加する必要がある答えを見つけました。elementInfo.name = "OrderItemDTO"; elementInfo.type = new OrderItemDTO().getClass(); info.elementType = elementInfo;

于 2013-11-26T09:26:57.010 に答える