[英]Android Login & Registration using Web service or ASP.NET denying a passed strings with KSoap2
[英]Consuming asp.net XML web service in android using ksoap2
我正在嘗試使用Ksoap2在Android中使用ASP.NET Web服務。 Web服務在瀏覽器中返回XML響應,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
-<Students>
-<student>
<stdName>Maria</stdName>
<stdRollNo>1</stdRollNo>
-</student>
-<student>
<stdName>Anna</stdName>
<stdRollNo>2</stdRollNo>
-</student>
-</Students>
在Android中使用下面給出的代碼調用此服務時,我得到一個例外:
Object response=null
try {
httpTransport.call(soap_action,envelope);
response=envelope.bodyIn;
Log.v("response is ", response.toString());
} catch(Exception e) {
e.getMessage();
}
例外:
response: "SoapFault" -faultcode:'soap:server' faultstrings: 'Server was not able to process request' object reference was not set to instance of an object"
我根據Stackoverflow上給出的不同建議對這段代碼進行了更改
SoapObject response=null
try{
httpTransport.call(soap_action,envelope);
response=(SoapObject)envelope.bodyIn;
Log.v("response is ", response.toString());
} catch(Exception e){
e.getMessage();
}
和
SoapObject response=null
try{
httpTransport.call(soap_action,envelope);
response=(SoapObject)envelope.getresponse();
Log.v("response is ", response.toString());
} catch(Exception e){
e.getMessage();
}
但例外情況則變為:
java.lang.classCastexception
關於發生了什么的任何想法?
您需要:1 /指定您的方法名稱(在ASP.Net代碼中定義):webMethName。 2 /使用SoapPrimitive而不是SoapObject,它就是你將獲得Web服務的地方。
請使用以下代碼編輯您的代碼塊:
String resText = "";
try {
// Invoke web service
httpTransport.call(soap_action + webMethName, envelope);
// Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
// Assign it to resText variable
resText = response.toString();
}
catch (Exception e) {
//Print error
e.printStackTrace();
//Assign error message to resText
resText = "Error occured";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.