连接到使用SOAPpy的python webservice的Android客户端

时间:2011-08-29 17:17:08

标签: java android soap ksoap2 soapui

我是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()

1 个答案:

答案 0 :(得分:0)

这就是我所做的和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;
}
}