【问题标题】:Android client connecting to python webservice that uses SOAPpy连接到使用 SOAPpy 的 Python Web 服务的 Android 客户端
【发布时间】:2011-08-29 17:17:08
【问题描述】:

我是 SOAP 编程的新手,正在为我的 android 应用程序寻找能够与用 SOAPpy 编写的 python web 服务进行通信的方法。我在互联网上发现使用套接字进行通信可能是其中一种选择,但除此之外,我可以使用 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()

【问题讨论】:

    标签: java android soap ksoap2 soapui


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-17
      • 2015-08-23
      • 2011-08-15
      • 1970-01-01
      • 1970-01-01
      • 2010-12-19
      • 1970-01-01
      相关资源
      最近更新 更多