1
我有Android應用程序,其中一些數據發送到.NET Web服務(WCF不,簡單的Web服務) 的Android應用程序,我有課,在服務器上實現KvmSerializable接口kSoap2發送收集
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服務方法
[的WebMethod]
public void SaveOrder(OrderDTO order)
{
try
{
// do somthing
}
catch (Exception e)
{
}
finally
{
}
}
我有成功的呼叫從機器人,現場所有人和訂購日期這種方法是正確填寫,但產品字段爲空(不爲空,只是空)
我嘗試使用數組,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 =新的PropertyInfo(); elementInfo.name =「OrderItemDTO」; elementInfo.type = new OrderItemDTO()。getClass(); \t \t \t \t info.elementType = elementInfo; – 2011-04-20 09:36:52