私はsoap webservicesを使用して1つの計算例を開発しました.それは私のエミュレーターでうまく機能しています.しかし、私のAndroidの実際のデバイスでは機能しません.
disは私のコードです:
package org.web.frontend.calculator;
import java.io.IOException;
import java.net.SocketException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.transport.ServiceConnection;
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.util.Log;
public class AndroidWSDLFrontEnd extends Activity {
private String METHOD_NAME ="sum";
private String NAMESPACE = "http://calculator.backend.web.org";
private String SOAP_ACTION = NAMESPACE + METHOD_NAME; // NAMESPACE + method name
private static final String URL = "http://192.168.1.168:8085/Calculation/services /Calculate?wsdl"; // you must use ipaddress here, don’t use Hostname or localhost
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.txtAddition);
try
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("i", 15);
request.addProperty("j", 10);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION,envelope);
Object result = envelope.getResponse();
System.out.println("Result : " + result.toString());
((TextView) findViewById (R.id.txtAddition)).setText("Addition : "+result.toString());
} catch (SocketException E) {
E.printStackTrace();
((TextView) findViewById (R.id.txtAddition)).setText("ERROR: " + E.getClass().getName() + ":" + E.getMessage());
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
私を助けてください。