2011-08-29 55 views
0

我是SOAP编程的新手,正在为我的android应用程序寻找能够与使用SOAPpy编写的python webservice进行通信的方式。我在互联网上发现使用套接字进行通信可能是其中一种选择,但除此之外,我可以使用HTTP/HTTPS来做到这一点吗? WifiPositioningSoapAPI()包含允许我操作存储数据的XML文件的函数。Android客户端连接到使用SOAPpy的python webservice

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

回答

0

这就是我所做的和getPassword来()是对的.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; 
} 
}