我是Android新手。任何人都可以借助任何示例或源代码帮助我开始使用Soap服务吗? 提前致谢
答案 0 :(得分:2)
如果您的网络服务是基于.Net的话,请使用此方法:
private static SoapObject callWebServiceMethod(String url,
String namespace, String methodName,
HashMap<String, Object> parameters, String soapAction)
throws Exception {
Log.i("WebService", "URL: " + url);
Log.i("WebService", "MethodName: " + methodName);
URL myurl = new URL(url);
URLConnection connection = myurl.openConnection();
connection.setConnectTimeout(20 * 1000);
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK)
{
httpConnection.disconnect();
SoapObject request = new SoapObject(namespace, methodName);
if (parameters != null) {
String[] keys = new String[0];
keys = (String[]) parameters.keySet().toArray(keys);
Object[] vals = (Object[]) parameters.values().toArray();
for (int i = 0; i < parameters.size(); i++) {
request.addProperty(keys[i], vals[i]);
Log.i("WebService", keys[i] + ": " + vals[i]);
}
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(url,
TimeOutInSeconds * 1000);
androidHttpTransport.call(soapAction, envelope);
SoapObject so = (SoapObject) envelope.getResponse();
return so;
}
else
{
httpConnection.disconnect();
}
}
用于下载Ksoap库use this link
答案 1 :(得分:1)
要在android中的SOAP Service中使用,你需要看下面的Parse Soap参考:
获取在你的android项目中使用的ksoap jar下面是使用ksoap库调用soap的Web服务类。