こんにちは、Ksoap2 ライブラリを使用して次のタイプの応答を解析していますが、結果を取得するのに成功していません。私の要求は次のようなものです。
<soapenv:Header/>
<soapenv:Body>
<tem:Register>
<tem:user>
<jir:Area>testArea</jir:Area>
<jir:AvailableBalance>0</jir:AvailableBalance>
<jir:CityId>1</jir:CityId>
<jir:Email>test@test.com</jir:Email>
<jir:FullName></jir:FullName>
<jir:Gender>M</jir:Gender>
<jir:Mobile>111111111</jir:Mobile>
<jir:Password>acxcsgsdvs</jir:Password>
<jir:Phone>111111111</jir:Phone>
<jir:SecurityAnswer>testQ</jir:SecurityAnswer>
<jir:SecurityQuestion>TestAb</jir:SecurityQuestion>
<jir:Username>sdf</jir:Username>
</tem:user>
</tem:Register>
</soapenv:Body>
ksoap2 ライブラリを使用して、次のような応答を正常に作成しました。
Register{user{Area=test; AvailableBalance=150; CityId=1; Email=test@test.com; FullName=Priyank; Gender=M; Mobile=9909957148; Password=testp; Phone=9909957148; SecurityAnswer=MyAns; SecurityQuestion=MyQues; Username=t; }}
しかし、私の問題は、値がユーザータグに追加されていないため、次のような例外が発生することです:
Object reference not set to an instance of an object.
ksoap2ライブラリを使用してこのタイプの応答を解析するにはどうすればよいか、これについて返信してください。
これは、応答の解析に使用しているヘルパー クラスです。
public class KSOAPHelper {
private static final String TAG = "KSOAPHelper : KSOAP Helper";
private static final String SOAP_ACTION = "http://tempuri.org/IUserService/";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "my url"
// Method names
public static final String REGISTER = "Register";
public static final String LOGIN = "Login";
public static final String LOGOUT = "Logout";
public static final String PROFILEDETAILS = "ProfileDetails";
public static Object getResponce(LinkedHashMap<String, String> inputParams, String methodName, final Context context) {
if (Utility.isConnectionAvailable) {
final String soap_action = SOAP_ACTION + methodName;
Log.d(TAG, soap_action);
SoapObject request = new SoapObject(NAMESPACE, methodName);
SoapObject user = new SoapObject(NAMESPACE, "user");
for (String param : inputParams.keySet()) {
Log.d(TAG, param + " : " + inputParams.get(param));
user.addProperty(param, inputParams.get(param));
}
request.addSoapObject(user);
Log.d(TAG, "SOAP Request : " + request);
/*
* Set the web service envelope
*/
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
// soapEnvelope.implicitTypes = true;
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE httpTransportSE = new HttpTransportSE(URL);
try {
httpTransportSE.call(soap_action, soapEnvelope);
if (soapEnvelope.bodyIn instanceof SoapFault) {
String strFault = ((SoapFault) soapEnvelope.bodyIn).faultstring;
Log.v(TAG, "Fault string : " + strFault);
} else {
Object object = soapEnvelope.getResponse();
return object;
}
} catch (Exception e) {
if (e instanceof SocketException || e instanceof IOException) {
if (context instanceof Activity) {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
}
}
e.printStackTrace();
}
} else {
if (context instanceof Activity) {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
}
Log.d(TAG, "Internet Connection is not available");
}
return null;
}