gpt4 book ai didi

android - 使用 ksoap2 时出现 org.xmlpull.v1.xmlpullparserexception 预期的 start_tag 错误

转载 作者:太空狗 更新时间:2023-10-29 13:26:28 28 4
gpt4 key购买 nike

我使用 ksoap2 通过 Web 服务连接 .NET。这是我的数据集

public DataSet getphimall()
{
DataSet ds1 = new DataSet();
try
{
SqlConnection cnn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=EMHAUI;Integrated Security=True");
SqlCommand cmd = new SqlCommand("sp_GetAllSemester_ad", cnn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds1);
return ds1;
}
catch (Exception e)
{
return null;
}
}

这是我的网络服务

[WebMethod]
public DataSet getSM()
{
Class1 phim1 = new Class1();

return phim1.getphimall();
}

这是我的 javaconnector 类

public class getSM {
String tenphim;
String daodien;
private static final String SOAP_ACTION = "http://tempuri.org/getSM";
private static final String METHOD_NAME = "getSM";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://10.0.2.2:50532/wsAndroid.asmx";
public getSM getallphim()
{



SoapObject table = null;
SoapObject client = null;
SoapObject tableRow = null;
SoapObject responseBody = null;
AndroidHttpTransport transport = null;
SoapSerializationEnvelope sse = null;
//cái này trong tut viết thế, mình lười đổi tên


sse = new SoapSerializationEnvelope(SoapEnvelope.VER11);
sse.addMapping(NAMESPACE, "getSM", this.getClass());
sse.dotNet = true;
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);

getSM setphim = new getSM();
try
{
client = new SoapObject(NAMESPACE, METHOD_NAME);
sse.setOutputSoapObject(client);
sse.bodyOut = client;
androidHttpTransport.call(SOAP_ACTION, sse);

responseBody = (SoapObject) sse.getResponse();
responseBody = (SoapObject) responseBody.getProperty(1);
table = (SoapObject) responseBody.getProperty(0);
tableRow = (SoapObject) table.getProperty(0);
setphim.daodien = tableRow.getProperty("ID").toString();
setphim.tenphim = tableRow.getProperty("SemesterName").toString();
return setphim;

} catch (Exception e)
{
setphim.daodien = e.toString();
setphim.tenphim = e.toString();
return setphim;
}

}}

但是当我运行我的模拟器时,我有一个错误org.xmlpull.v1.xmlpullparserexception 预期 start_tag 错误请帮我!谢谢

最佳答案

您遇到的异常可能有多种原因。

  1. 错误的 SOAP 调用参数:尝试通过查看 WSDL 文件来确认 NAMESPACE、ACTION、METHOD 和 URL 的值是否正确
  2. 来自服务器的无效响应:尝试记录服务器发送给您的响应并检查您是否获得了结构良好的正确 XML

    androidHttpTransport.debug = true;

    //执行请求

    androidHttpTransport.responseDump;//来自服务器的响应字符串

  3. 信封的
  4. dotNet 属性:尝试使用 soapEnvelope.dotNet=true

关于android - 使用 ksoap2 时出现 org.xmlpull.v1.xmlpullparserexception 预期的 start_tag 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20778846/

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