java通过ksoap调用_java – Ksoap:将用户定义的类作为参数传...

我花了几天时间试图找出如何使我的用户定义的java类可序列化,以便我可以将它作为参数发送到android ksoap调用c#web方法.

下面是我的代码和调用webservice时在logcat中抛出的异常,如果我得到即时答复或帮助,我将感激不尽.

我的java类XY.java:

import org.ksoap2.serialization.KvmSerializable;

import org.ksoap2.serialization.PropertyInfo;

public class XY implements KvmSerializable {

public static Class XY_CLASS = XY.class;

private String MyNum;

private String OppPhoneNum;

private String Name;

public XY()

{

}

public XY(String MyNum, String Name, String oppNum)

{

this.MyNum = MyNum;

this.Name = Name;

this.OppPhoneNum = oppNum;

}

public String getPhoneNum() {

return MyNum;

}

public void setPhoneNum(String MyNum) {

this.MyNum = MyNum;

}

public String getName() {

return Name;

}

public void setName(String Name) {

this.Name = Name;

}

public String getOpponentPhoneNum() {

return OppPhoneNum;

}

public void setOpponentPhoneNum(String OppPhoneNum) {

this.OppPhoneNum = OppPhoneNum;

}

@Override

public Object getProperty(int arg0) {

switch(arg0)

{

case 0:

return MyNum;

case 1:

return OppPhoneNum;

case 2:

return Name;

}

return null;

}

@Override

public int getPropertyCount() {

// TODO Auto-generated method stub

return 3;

}

@Override

public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {

switch(index)

{

case 0:

info.type = PropertyInfo.STRING_CLASS;

info.name = "MyNum";

break;

case 1:

info.type = PropertyInfo.STRING_CLASS;

info.name = "OppPhoneNum";

break;

case 2:

info.type = PropertyInfo.STRING_CLASS;

info.name = "Name";

break;

default:break;

}

}

@Override

public void setProperty(int index, Object value) {

switch(index)

{

case 0:

MyNum = value.toString();

break;

case 1:

OppPhoneNum = value.toString();

break;

case 2:

Name = value.toString();

break;

default:

break;

}

}

}

C#等价类:

[Serializable]

public class XY

{

public System.String Name

{

get;

set;

}

public System.String MyNum

{

get;

set;

}

public System.String OppPhoneNum

{

get;

set;

}

}

这就是我从我的活动中使用kso??ap调用服务的方式:

private void unKnown(List entries)

{

//Initialize soap request + add parameters

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

PropertyInfo entriesProp =new PropertyInfo();

entriesProp.setName("entries");

entriesProp.setValue(entries);

entriesProp.setType(ArrayList.class);

//Use this to add parameters

request.addProperty(entriesProp);

//Declare the version of the SOAP request

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

envelope.setOutputSoapObject(request);

envelope.addMapping(NAMESPACE, "XY", XY.XY_CLASS);

envelope.dotNet = true;

try {

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

//this is the actual part that will call the webservice

androidHttpTransport.call(SOAP_ADDCONTACTS, envelope);

// Get the SoapResult from the envelope body.

if (envelope.bodyIn instanceof SoapFault)

{

String str= ((SoapFault) envelope.bodyIn).faultstring;

Log.i("", str);

}

else

{

SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;

if(resultsRequestSOAP != null)

{

Log.i("AddContacts", "Adding Contacts succeeded");

}

}

}

catch (Exception e)

{

e.printStackTrace();

}

}**

Logcat例外:

java.lang.RuntimeException: Cannot Serialize: [XY .....**

注意:我正在尝试将XY对象列表作为参数传递给Web服务方法.

我将不胜感激任何帮助 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值