简体   繁体   English

Android客户端连接到使用SOAPpy的python Web服务

[英]Android client connecting to python webservice that uses SOAPpy

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. 我是SOAP编程的新手,正在寻找让我的android应用程序能够与用SOAPpy编写的python webservice通信的方法。 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 do so? 我在互联网上发现使用套接字通信可能是一种选择,但除此之外,我可以使用HTTP / HTTPS这样做吗? WifiPositioningSoapAPI() contain functions that allows me to manipulate the XML files where the data are stored. 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()

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) 这就是我所做的,并且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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM