我正在使用Kapap2库来进行Soap Web服务,因为android中没有直接的方法可以这样做。使用后我成功从服务器获得回复。它有起始标签""并且xml响应也以此标记结束。但我没有结束标签。这是我得到的。
<NewDataSet>
<Table>
<AgentHangup>true</AgentHangup>
<CallDetailId>140120151439395690100016</CallDetailId>
<CallID>3171B65415000200</CallID>
<CorrelatorId />
<CallDuration>9</CallDuration>
<EncryptedCall>false</EncryptedCall>
<CallDate>2015/01/14 14:39:39</CallDate>
<CalledBy>9010</CalledBy>
<CalledTo>9000</CalledTo>
<IsExternal>false</IsExternal>
<RecorderType>PRIMARY</RecorderType>
<FirstName>fawad</FirstName>
<LastName>khan</LastName>
<Comments />
<FlagID>1</FlagID>
<FlagImage>1.gif</FlagImage>
<AF>C:\Program Files (x86)\Alcatel-Lucent\OmniPCXRecord Suite\OmniPCXRecord\OmniPCXRecordAudio\Repository\from\150114\0004\32_14012015 143939599_0016_9010.wav</AF>
<CallDirection>O</CallDirection>
<FLAGTEXT>Training required</FLAGTEXT>
<Archive>false</Archive>
<ExtensionValue>9010</ExtensionValue>
<GraphValue />
</Table>
<Table>
<AgentHangup>true</AgentHangup>
<CallDetailId>140120151439382290010016</CallDetailId>
<CallID>3171B65415000200</CallID>
<CorrelatorId />
<CallDuration>11</CallDuration>
<EncryptedCall>false</EncryptedCall>
<CallDate>2015/01/14 14:39:38</CallDate>
<CalledBy>9010</CalledBy>
<CalledTo>9001</CalledTo>
<IsExternal>false</IsExternal>
<RecorderType>PRIMARY</RecorderType>
<FirstName>Jack</FirstName>
<LastName>Rayan</LastName>
<Comments />
<FlagID>1</FlagID>
<FlagImage>1.gif</FlagImage>
<AF>C:\Program Files (x86)\Alcatel-Lucent\OmniPCXRecord Suite\OmniPCXRecord\OmniPCXRecordAudio\Repository\from\150114\0002\30_14012015 143938287_0016_9001.wav</AF>
<CallDirection>I</CallDirection>
<FLAGTEXT>Training required</FLAGTEXT>
<Archive>false</Archive>
<ExtensionValue>9001</ExtensionValue>
<GraphValue />
</Table>
<Table>
<AgentHangup>false</AgentHangup>
<CallDetailId>140120151439384490000016</CallDetailId>
<CallID>2A71B65414000200</CallID>
<CorrelatorId />
<CallDuration>11</CallDuration>
<EncryptedCall>false</EncryptedCall>
<CallDate>2015/01/14 14:39:38</CallDate>
<CalledBy>9010</CalledBy>
<CalledTo>9000</CalledTo>
<IsExternal>false</IsExternal>
<RecorderType>PRIMARY</RecorderType>
<FirstName>adnan</FirstName>
<LastName>akhtar</LastName>
<Comments />
<FlagID>1</FlagID>
<FlagImage>1.gif</FlagImage>
<AF>C:\Program Files (x86)\Alcatel-Lucent\OmniPCXRecord Suite\OmniPCXRecord\OmniPCXRecordAudio\Repository\from\150114\0001\31_14012015 143938537_0016_9000.wav</AF>
<CallDirection>I</CallDirection>
<FLAGTEXT>Training required</FLAGTEXT>
<Archive>false</Archive>
<ExtensionValue>9000</ExtensionValue>
<GraphValue />
</Table>
<Table>
<AgentHangup>false</AgentHangup>
<CallDetailId>140120151439354290010015</CallDetailId>
<CallID>3171B65415000200</CallID>
<CorrelatorId />
<CallDuration>1</CallDuration>
<EncryptedCall>false</EncryptedCall>
<CallDate>2015/01/14 14:39:35</CallDate>
<CalledBy>9010</CalledBy>
<CalledTo>9001</CalledTo>
<IsExternal>false</IsExternal>
<RecorderType>PRIMARY</RecorderType>
<FirstName>Jack</FirstName>
<LastName>Rayan</LastName>
<Comments />
<FlagID>1</FlagID>
<FlagImage>1.gif</FlagImage>
<AF>C:\Program Files (x86)\Alcatel-Lucent\OmniPCXRecord Suite\OmniPCXRecord\OmniPCXRecordAudio\Repository\from\150114\0002\28_14012015 143935505_0015_9001.wav</AF>
<CallDirection>I</CallDirection>
<FLAGTEXT>Training required</FLAGTEXT>
<Archive>false</Archive>
<ExtensionValue>9001</ExtensionValue>
<GraphValue />
</Table>
<Table>
<AgentHangup>true</AgentHangup>
<CallDetailId>140120151439355890100015</CallDetailId>
<CallID>3171B65415000200</CallID>
<CorrelatorId />
<CallDuration>2</CallDuration>
<EncryptedCall>false</EncryptedCall>
<CallDate>2015/01/14 14:39:35</CallDate>
<CalledBy>9010</CalledBy>
<CalledTo>9001</CalledTo>
<IsExternal>false</IsExternal>
<RecorderType>PRIMARY</RecorderType>
看到我们在启动时没有这样的结束标记(在本例中为NewDataSet)
我正在使用以下课程来获得回复:
public class SoapRequests {
private static final boolean DEBUG_SOAP_REQUEST_RESPONSE = true;
private static final String MAIN_REQUEST_URL = "http://192.168.2.152/OmniPCXRecord/recordservice.asmx";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ACTION = "http://tempuri.org/";
private static String SESSION_ID;
public static String Toaster=null ;
private final void testHttpResponse(HttpTransportSE ht) {
ht.debug = DEBUG_SOAP_REQUEST_RESPONSE;
if (DEBUG_SOAP_REQUEST_RESPONSE) {
Log.v("SOAP RETURN", "Request XML:\n" + ht.requestDump);
Log.v("SOAP RETURN", "\n\n\nResponse XML:\n" + ht.responseDump)
;
Toaster=ht.responseDump;
}
}
public String getData(String fValue) {
String data = null;
String methodname = "SearchCalls";
SoapObject request = new SoapObject(NAMESPACE, methodname);
//3
request.addProperty("username", "admin");
//
request.addProperty("password", "admin");
//5
request.addProperty("FirstNameCriteria", "");
//6
request.addProperty("FirstName", "");
//7
request.addProperty("LastNameCriteria", "");
//8
request.addProperty("LastName", "");
//9
request.addProperty("GroupSearchOption", "");
//10
request.addProperty("GroupName", "");
//11
request.addProperty("EncryptedCallsCriteria", "");
//12
request.addProperty("AssociatedAgentCriteria", "");
//13
request.addProperty("CalledByCriteria", "");
//14
request.addProperty("CalledBy", "");
//15
request.addProperty("CalledToCriteria", "");
//16
request.addProperty("CalledTo", "");
//17
request.addProperty("CalledDateSearchCriteria", "Past_N_days");
//18
request.addProperty("NumberOfDays", "1");
//19
request.addProperty("StartDate", "");
//20
//I have round about 100 of parameters to send and they are generated successfully
//i am sharing here few just for example
Log.v("Final Property is",request.toString());
SoapSerializationEnvelope envelope = getSoapSerializationEnvelope(request);
HttpTransportSE ht = getHttpTransportSE();
try {
ht.call(SOAP_ACTION + methodname, envelope);
testHttpResponse(ht);
SoapPrimitive resultsString = (SoapPrimitive)envelope.getResponse();
// List<HeaderProperty> COOKIE_HEADER = (List<HeaderProperty>) ht.getServiceConnection().getResponseProperties();
// for (int i = 0; i < COOKIE_HEADER.size(); i++) {
// String key = COOKIE_HEADER.get(i).getKey();
// String value = COOKIE_HEADER.get(i).getValue();
//
// if (key != null && key.equalsIgnoreCase("set-cookie")) {
// SoapRequests.SESSION_ID = value.trim();
// Log.v("SOAP RETURNCookiee", "Cookie :" + SoapRequests.SESSION_ID+key);
// // Log.v("SOAP RETURNCookiee", "Cookie :" + SoapRequests.SESSION_ID);
// break;
// }
// }
data = resultsString.toString();
} catch (SocketTimeoutException t) {
t.printStackTrace();
} catch (IOException i) {
i.printStackTrace();
} catch (Exception q) {
q.printStackTrace();
}
return data;
}
private final SoapSerializationEnvelope getSoapSerializationEnvelope(SoapObject request) {
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//change from orgnl
//envelope.dotNet = true;
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setAddAdornments(false);
envelope.setOutputSoapObject(request);
return envelope;
}
private final HttpTransportSE getHttpTransportSE() {
HttpTransportSE ht = new HttpTransportSE(Proxy.NO_PROXY,MAIN_REQUEST_URL,6000);
ht.debug = true;
ht.setXmlVersionTag("<?xml version=\"1.0\" encoding= \"UTF-8\" ?>");
return ht;
}
}
请注意,我正在使用此&#34; SoapPrimitive resultsString =(SoapPrimitive)envelope.getResponse();&#34;以字符串格式获取响应。 现在告诉我为什么xml中没有以字符串格式出现的结束标记?什么问题? Log中没有任何内容,一切都很好。