I'm trying to call a web service from my Android app. I deployed a web service that inserts a record (product barcode, product name) with Hibernate in Java and I wrote an activity to test it.
When I run it on my AVD I got a connectionException : Connection refused
Here is my code:
package com.market_helper.app;
import android.R.string;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.serialization.PropertyInfo;
public class Market_helper_androidActivity extends Activity {
private static final String SOAP_ACTION = "http://localhost:7675/market_helper/services/Main";
private static final String METHOD_NAME = "insertProduct";
private static final String NAMESPACE = "http://localhost:7675/market_helper/services/";
private static final String URL = "http://localhost:7675/market_helper/services/Main?wsdl";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("barCode", "12345");
request.addProperty("productName", "abc");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Object result = envelope.getResponse();
} catch (Exception e) {
e.printStackTrace();
}
}
}
It's my first webservice on Android and I'm not sure if the code is right. I'm calling a method that called insertProduct(String barCode,String productName)
. The web service is working and tested.
private static final String SOAP_ACTION = "http://localhost:7675/market_helper/services/Main";
You have given LocalHost
try with ip address instead of LocalHost
lik this
private static final String SOAP_ACTION = "http://10.120.159.87:7675/market_helper/services/Main";