gpt4 book ai didi

java - 调用网络服务时出错

转载 作者:行者123 更新时间:2023-12-01 15:23:05 26 4
gpt4 key购买 nike

我已经完成了我的 asmx,它是使用 .net c# 开发的,并且运行良好

但是当我需要使用 java android 调用时,我发现了一个错误错误:java.lang.ClassCastException:org.ksoap2.serialization.SoapObject 无法转换为 org.ksoap2.serialization.SoapPrimitive

结果显示在我的 asmx 上:

<customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<customerID>1</customerID>
<companyName>ABC</companyName>
<contactName>Jack</contactName>
<customerID>2</customerID>
<companyName>SS Company</companyName>
<contactName>Mary</contactName>
</customer>

我的java cs:

        public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView)findViewById(R.id.textView1);

SoapObject Request = new SoapObject (NAMESPACE, METHOD_NAME);
Request.addProperty("custID", "member");

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);

AndroidHttpTransport aht = new AndroidHttpTransport(URL);

try
{
aht.call(SOAP_ACTION, soapEnvelope);
SoapObject resultString = (SoapObject) soapEnvelope.getResponse();
tv.setText(resultString.toString());
}
catch(Exception e)
{
tv.setText(e.toString());
}
}

如果我使用http://www.w3schools.com/webservices/tempconvert.asmx,上面的代码就可以运行

最佳答案

我已经解决了

           SoapObject resultString = (SoapObject) soapEnvelope.getResponse();           

String addon = "";
for(int i =0;i<resultString.getPropertyCount();i++)
{
SoapObject array2 = (SoapObject) resultString .getProperty(i);
addon = (addon + "ID = " + array2.getProperty(0).toString() + array2.getProperty(1).toString() + array2.getProperty(2).toString() + "\n");
}
tv.setText(addon.toString());

关于java - 调用网络服务时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10580993/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com