[英]Android client connecting to python webservice that uses SOAPpy
我是SOAP編程的新手,正在尋找讓我的android應用程序能夠與用SOAPpy編寫的python webservice通信的方法。 我在互聯網上發現使用套接字通信可能是一種選擇,但除此之外,我可以使用HTTP / HTTPS這樣做嗎? WifiPositioningSoapAPI()包含使我能夠操作存儲數據的XML文件的函數。
class StartSOAPServer:
def __init__(self):
api = WifiPositionSoapAPI()
handler = SOAPpy.SOAPServer(("", Config.SOAP_PORT))
handler.registerObject(api, Config.NAMESPACE)
print "SOAP server running at IP Address %s port %s." % (socket.gethostbyname(socket.gethostname() ), Config.SOAP_PORT)
handler.serve_forever()
這就是我所做的,並且getPassword()位於我在python服務器上與之交互的.py之一(只是一個包含很多.py文件的文件夾)
public class WifiPositioningServices {
private final String NAMESPACE = "urn:WifiPositioningSystem";
//private final String METHOD_NAME = "GetPassword";
//private final String SOAP_ACTION = "urn:WifiPositioningSystem/GetPassword";
private final String URL = "http://xxx.xxx.xxx.xxx:8080";
private SoapSerializationEnvelope envelope;
public WifiPositioningServices(){
}
public String[] getPassword(String loginID){
String[] temp = null;
SoapObject request = new SoapObject(NAMESPACE, "GetPassword");
PropertyInfo quotesProperty = new PropertyInfo();
quotesProperty.setName("LoginID");
quotesProperty.setValue(loginID);
quotesProperty.setType(String.class);
request.addProperty(quotesProperty);
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
String result = "";
HttpTransportSE httpRequest = new HttpTransportSE(URL);
try
{
httpRequest.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
result = response.toString();
temp = result.split(";");
}
catch(Exception e)
{
e.printStackTrace();
}
return temp;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.