问题描述
我试图从 SOAP Web 服务获得响应,但响应总是像“字符串或数据将被截断”一样。如果第一个节点是表,但它在此服务中更改为“NewDataSet”,则获取响应的方式是有效的,如下所示。在桌面上调用相同的服务时,即使传递的参数也有效。使用的链接都是正确的,可以在其他代码中使用。
响应示例:
<NewDataSet><record><id>10553</id><errormessage>Record(s) Inserted Successfully.</errormessage</record></NewDataSet>
PVAsyncCall1.java
public class PVAsyncCall1 extends AsyncTask<String,Void,String> {
private final Activity activity;
private String methodName = "SaveDownloadDocument";
private final Map<String,String> mapRequestTag;
private final OnExecutResponse onExecutResponse;
private final String NAME_SPACE = "http://ws.gajeratrust.org/";
private String SOAP_ACTION = "";
private SoapObject resultRequestSOAP;
private String response = "";
ProgressDialog pDialog;
boolean isDelay;
boolean isProgressDialogVisible;
public PVAsyncCall1(Activity activity,String methodName,Map<String,String> mapRequestTag,boolean isProgressDialogVisible,OnExecutResponse onExecutResponse) {
this.activity = activity;
this.methodName = methodName;
this.mapRequestTag = mapRequestTag;
this.onExecutResponse = onExecutResponse;
this.isProgressDialogVisible = isProgressDialogVisible;
SOAP_ACTION = NAME_SPACE + methodName;
pDialog = new ProgressDialog(activity);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
if (isProgressDialogVisible) {
pDialog.setMessage("Loading...");
pDialog.show();
}
}
@Override
protected String doInBackground(String... strings) {
SoapObject request = new SoapObject(NAME_SPACE,methodName);
if (mapRequestTag.size() != 0) {
for (Map.Entry<String,String> map : mapRequestTag.entrySet()) {
request.addProperty(map.getKey(),map.getValue());
}
}
Log.e("Url_" + methodName,request.toString());
try {
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.setoutputSoapObject(request);
HttpTransportSE httpTransportSE = new HttpTransportSE(com.example.misgajeratrust.Common.Global_App.Url);
httpTransportSE.call(SOAP_ACTION,envelope);
resultRequestSOAP = (SoapObject) envelope.getResponse();
response = resultRequestSOAP.toString();
Debug.e("Result_" + methodName,response);
} catch (Exception e) {
e.printstacktrace();
Log.e("LOG","" + e.toString());
pDialog.dismiss();
response = "";
}
return response;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
if (!response.trim().equals("")) {
SoapObject newDataSet = resultRequestSOAP.hasProperty(com.example.misgajeratrust.Common.Get_Parameter_Tag.newDataSet) ?
(SoapObject) resultRequestSOAP.getProperty(com.example.misgajeratrust.Common.Get_Parameter_Tag.newDataSet) : null;
onExecutResponse.onSuccess(newDataSet,"",false);
} else {
Toast.makeText(activity,"Server Time-out",Toast.LENGTH_SHORT).show();
}
pDialog.dismiss();
}
public interface OnExecutResponse {
void onSuccess(SoapObject NewDataSet,String ErrorCode,String ErrorMessage,String AlertTypeCode,boolean isException);
}
}
private void saveDownloadDocument() {
Map<String,String> mapPassingTag = new LinkedHashMap<>();
mapPassingTag.put(Pass_Parameter_Tag.p_numDownloadID,"0");
mapPassingTag.put(Pass_Parameter_Tag.p_datDownloadDate,"11 January 2021");
mapPassingTag.put(Pass_Parameter_Tag.p_numSchoolID,"11");
mapPassingTag.put(Pass_Parameter_Tag.p_strAcademicYear,"2020-2021");
mapPassingTag.put(Pass_Parameter_Tag.p_numSchoolClassID,"28");
mapPassingTag.put(Pass_Parameter_Tag.p_numDivisionID,"97");
mapPassingTag.put(Pass_Parameter_Tag.p_numCategoryID,"83");
mapPassingTag.put(Pass_Parameter_Tag.p_strFileName,"Example.pdf");
mapPassingTag.put(Pass_Parameter_Tag.p_strDescription,"Testing");
mapPassingTag.put(Pass_Parameter_Tag.p_strFileExtension,".pdf");
mapPassingTag.put(Pass_Parameter_Tag.p_datValidFromDate,"11 January 2021");
mapPassingTag.put(Pass_Parameter_Tag.p_datValidToDate,"11 January 2021");
mapPassingTag.put(Pass_Parameter_Tag.p_numIsActive,"1");
mapPassingTag.put(Pass_Parameter_Tag.p_numEnteredBy,"1234");
mapPassingTag.put(Pass_Parameter_Tag.p_strIPAddress,Global_App.Ip_Address(getActivity()));
mapPassingTag.put(Pass_Parameter_Tag.p_strLoginYear,Global_App.LoginYear);
new PVAsyncCall1(getActivity(),Global_App.SaveDownloadDocument,mapPassingTag,true,new PVAsyncCall1.OnExecutResponse() {
@Override
public void onSuccess(SoapObject NewDataSet,boolean isException) {
if (NewDataSet != null) {
for (int i = 0; i < NewDataSet.getPropertyCount(); i++) {
PropertyInfo property = new PropertyInfo();
NewDataSet.getPropertyInfo(i,property);
String name = property.getName();
if (name.equalsIgnoreCase(Get_Parameter_Tag.record)) {
SoapObject record = (SoapObject) NewDataSet.getProperty(i);
if (record.hasProperty(Get_Parameter_Tag.errormessage)) {
String Message = record.getProperty(Get_Parameter_Tag.errormessage)
.toString();
new OkDialog1(getActivity(),Message);
} else {
new OkDialog1(getActivity(),"File not uploaded.");
}
}
}
} else {
new OkDialog1(getActivity(),"Some problem.");
}
}
}).execute();
}
没有错误消息,即使在调试时,响应为空。 谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)