Android 为什么';Web服务是否可以手动工作?
我有不止一种方法的webservice。我使用firefox soaclient插件来测试它们。所有方法都能正常工作。到目前为止,这些都是正常的。我在android上编写了一个库来调用这些.NETWebService。我有方法,第一个准备信封,另一个调用方法。除一种方法外,所有方法都以这种方式工作。我从我的库中为不起作用的方法准备了信封,并在FirefoxSOAP客户端上使用这个信封,它以正确的方式返回我的响应。我自己调用web服务的方法没有错误,只返回空结果。可能是什么错误Android 为什么';Web服务是否可以手动工作?,android,web-services,soap,Android,Web Services,Soap,我有不止一种方法的webservice。我使用firefox soaclient插件来测试它们。所有方法都能正常工作。到目前为止,这些都是正常的。我在android上编写了一个库来调用这些.NETWebService。我有方法,第一个准备信封,另一个调用方法。除一种方法外,所有方法都以这种方式工作。我从我的库中为不起作用的方法准备了信封,并在FirefoxSOAP客户端上使用这个信封,它以正确的方式返回我的响应。我自己调用web服务的方法没有错误,只返回空结果。可能是什么错误 private v
private void createEnvelope() {
// Her bir parametrenin kalıbı
String params = "<%s>%s</%s>";
// Her parametre kalıbına değer atandığında geçici olarak tutulan string
String paramsTemp = "";
// Hazırlanan tüm parametrelerin tutulduğu değişken
String paramsAll = "";
// Parametreler ekleniyor
for (int i = 0; i < parameterKeys.size(); i++) {
paramsTemp = String.format(params, parameterKeys.get(i),
parameterValues.get(i), parameterKeys.get(i));
paramsAll += paramsTemp;
}
// soap mesajını hazılıyoruz
String soapTemplate = "<?xml version=\"%s\" encoding=\"%s\"?>"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<soap:Body>" + "<%s xmlns=\"%s\">" + "%s" + "</%s>"
+ "</soap:Body>" + "</soap:Envelope>";
envelope = String.format(soapTemplate, version, charEncoding,
methodName, namespace, paramsAll, methodName);
Logger.log("request:" + envelope);
}
public String callWebService() {
createEnvelope();
// request parameters
HttpParams params = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, connectionTimeOut);
HttpConnectionParams.setSoTimeout(params, soTimeOut);
// set parameter
HttpProtocolParams.setUseExpectContinue(httpClient.getParams(), true);
// POST the envelope
HttpPost httppost = new HttpPost(url);
// add headers
httppost.setHeader("SOAPAction", soapAction);
httppost.setHeader("Content-Type", contentType);
try {
// the entity holds the request
HttpEntity entity = new StringEntity(envelope);
httppost.setEntity(entity);
// Response handler
ResponseHandler<String> rh = new ResponseHandler<String>() {
// invoked when client receives response
public String handleResponse(HttpResponse responseTemp)
throws ClientProtocolException, IOException {
// get response entity
HttpEntity entity = responseTemp.getEntity();
StatusLine statusLine = responseTemp.getStatusLine();
// read the response as byte array
StringBuffer out = new StringBuffer();
byte[] b = EntityUtils.toByteArray(entity);
// write the response byte array to a string buffer
out.append(new String(b, 0, b.length));
return out.toString();
}
};
response = httpClient.execute(httppost, rh);
} catch (Exception e) {
Log.v("Soap Service Exception:", e.toString());
}
// close the connection
httpClient.getConnectionManager().shutdown();
return response;
}
private void createEnvelope(){
//她的bir parametrenin kalıbı
字符串参数=“%s”;
//她的助手卡尔·比娜·德奥尔·阿坦德·格朗达·科里奇·奥拉拉克·图图图兰·斯林(kalıbına değer atandığnda geçici olarak tutulan string)
字符串paramsTemp=“”;
//哈兹·拉南·图图尔杜奥德·伊肯(Hazırlanan tüm Parameterlerin tutulduğu değişken)
字符串paramsAll=“”;
//埃克勒尼奥尔参数
对于(int i=0;i
编辑
logcat上的请求模板:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Method_Name xmlns="url">
<param1>12345</param1>
<param2>ügıtç</param2>
<param3>qwert</param3>
</Method_Name>
</soap:Body>
</soap:Envelope>
12345
ügıtç
qwert
logcat上的响应模板
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Method_Name_Response xmlns="url">
<Method_Name_Result>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Temp">
<xs:complexType>
<xs:sequence>
<xs:element name="response1" type="xs:long" minOccurs="0" />
<xs:element name="response2" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" />
</Method_Name_Result>
</Method_Name_Response>
</soap:Body>
</soap:Envelope>
具有相同信封的firefox插件上的响应模板
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Method_Name_Response xmlns="url">
<Method_Name_Result>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Temp">
<xs:complexType>
<xs:sequence>
<xs:element name="response1" type="xs:long" minOccurs="0" />
<xs:element name="response2" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<NewDataSet xmlns="">
<Temp diffgr:id="Temp1" msdata:rowOrder="0">
<response1>123456789</response1>
<response2>Android</response2>
</Temp>
</NewDataSet>
</diffgr:diffgram>
</Method_Name_Result>
</Method_Name_Response>
</soap:Body>
</soap:Envelope>
123456789
安卓
我发现了问题,土耳其语字符导致了错误。当我使用“ü”时,它会导致错误,当我不使用它时,它工作得很好。发布你的logcat
,如果可能的话wireshark
dump。我用模板结果编辑我的问题。由于信息的隐私性,我无法分享原始结果。