I am new to SOAP programming and is looking for ways for my android app to be able to communicate with a python webservice written in SOAPpy. I found on the internet that communicating using socket might be one of the choices but other that that, can i use HTTP/HTTPS to d开发者_Go百科o so? WifiPositioningSoapAPI() contain functions that allows me to manipulate the XML files where the data are stored.
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()
This is what i did and getPassword() is on one of the .py that i interact with on the python server (just a folder that have lots of .py files)
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;
}
}
精彩评论