Connection to a web service in Android Virtual Device <p>I have a web service with a WS-security. I can have access to this web service only with my machine IP address and only if I make the right WS configuration.</p> <p>So when testing it in Soap-ui, I get responses! and when testing connection in browser of my emulator, I get the wsdl page!</p> <p>But when implemented in my application, I can not call the web service! I'm making something really wrong and didn't get it!</p> <p>Is the URL I'm using for calling my web service right? Have I to configure the DNS server in the emulator? What have I to do ?</p> <p>Here is my SOAP request:</p> <pre><code> POST http://172.xxx.xxx.xxx:8080/wbb HTTP/1.1 Accept-Encoding: gzip,deflate Content-Type: text/xml;charset=UTF-8 SOAPAction: "" Content-Length: 1146 Host: 172.xxx.xxx.xxx:8080 Connection: Keep-Alive User-Agent: Apache-HttpClient/4.1.1 (java 1.5) &lt;soapenv:Envelope xmlns:ser="http://www.''''.com/wbb/service" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;soapenv:Header&gt;&lt;wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt; &lt;wsse:UsernameToken wsu:Id="UsernameToken-11"&gt; &lt;wsse:Username&gt;whatever2&lt;/wsse:Username&gt; &lt;wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"&gt;whatever3&lt;/wsse:Password&gt; &lt;wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"&gt;whatever4&lt;/wsse:Nonce&gt; &lt;wsu:Created&gt;whatever5&lt;/wsu:Created&gt; &lt;/wsse:UsernameToken&gt;&lt;/wsse:Security&gt;&lt;/soapenv:Header&gt; &lt;soapenv:Body&gt; &lt;ser:RechargeRequest&gt; &lt;ser:value1&gt;?&lt;/ser:value1&gt; &lt;ser:value2&gt;?&lt;/ser:value2&gt; &lt;!--Optional:--&gt; &lt;ser:value3&gt;?&lt;/ser:value3&gt; &lt;/ser:RechargeRequest&gt; </code></pre> <p> </p> <p>and my android code:</p> <pre><code> protected String doInBackground(String... params) { private static final String SOAP_ACTION = ""; private static final String NAMESPACE"http://www.'''''.com/wbb/ws"; private static final String METHOD_NAME="Recharge"; private static final String URL = "http://172.xxx.xxx.xxx:8080/wbb/wbb.wsdl"; SoapPrimitive response = null; String xml=""; SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); PropertyInfo p1 =new PropertyInfo(); p1.name = "value1"; p1.setValue(params[0]); request.addProperty(p1); PropertyInfo p2 =new PropertyInfo(); p2.name = "value2"; p2.setValue(params[1]); request.addProperty(p2); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); // create header Element[] header = new Element[1]; header[0] = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security"); Element usernametoken = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "UsernameToken"); usernametoken.setAttribute(null, "Id", "UsernameToken-1"); header[0].addChild(Node.ELEMENT,usernametoken); Element username = new Element().createElement(null, "n0:Username"); username.addChild(Node.IGNORABLE_WHITESPACE,"whatever2"); usernametoken.addChild(Node.ELEMENT,username); Element pass = new Element().createElement(null,"n0:Password"); pass.setAttribute(null, "Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"); pass.addChild(Node.TEXT, "whatever3"); usernametoken.addChild(Node.ELEMENT, pass); Element nonce = new Element().createElement(null, "n0:Nonce"); nonce.setAttribute(null, "EncodingType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"); nonce.addChild(Node.TEXT, "whatever3"); usernametoken.addChild(Node.ELEMENT, nonce); Element created = new Element().createElement(null, "n0:Created"); created.addChild(Node.TEXT, "whatever4"); usernametoken.addChild(Node.ELEMENT, created); // add header to envelope envelope.headerOut = header; Log.i("header", "" + envelope.headerOut.toString()); envelope.dotNet = false; envelope.bodyOut = request; envelope.setOutputSoapObject(request); //HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); URL url = null; try { url = new URL(URL); } catch (MalformedURLException e1) { e1.printStackTrace(); } HttpTransportSE androidHttpTransport = null; String host = url.getHost(); int port = url.getPort(); String file = url.getPath(); Log.d("Exception d", "host -&gt; " + host); Log.d("Exception d", "port -&gt; " + port); Log.d("Exception d", "file -&gt; " + file); androidHttpTransport = new KeepAliveHttpsTransportSE(host, port, file, 25000); Log.i("bodyout", "" + envelope.bodyOut.toString()); try { androidHttpTransport.debug = true; androidHttpTransport.call(SOAP_ACTION, envelope); xml = androidHttpTransport.responseDump; response = (SoapPrimitive)envelope.getResponse(); Log.i("myApp", response.toString()); } catch (SoapFault e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); Log.d("Exception Generated", ""+e.getMessage()); } return response; } </code></pre> <p>Sorry for my bad english and for the mistakes! </p>