0

Could anyone please help in processing the SOAP request and response from an android application.

I have followed the tutorial at http://www.c-sharpcorner.com/UploadFile/88b6e5/how-to-call-web-service-in-android-using-soap/

But when I run the application, it exits prematurely with the error

Unfortunately, has stopped.

I am running it in an emulator.

Can anyone please explain what I might be missing. Any example source code will be very useful.

4

1 回答 1

0

我有一个简单的代码给你。我们有一个按钮,我们将调用 helloworld 方法。

按钮世界方法;

    private static final String SOAP_ACTION1 = "http://tempuri.org/HelloWorld";
private static final String HelloWorldmethod = "HelloWorld";

    private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.168.1.5/MobileDemo/Demo.asmx";

    @Override
protected void onCreate(Bundle savedInstanceState) {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webservices_layout);

    Worldmethod= (Button)findViewById(R.id.Worldmethod);

            Worldmethod.setOnClickListener(this);

             @Override
           public void onClick(View v) {

    switch (v.getId()){
    case R.id.Worldmethod:

    try
    {

    methodbody= (TextView)findViewById(R.id.methodbody);

    SoapObject request1 = new SoapObject(NAMESPACE, HelloWorldmethod);

    // add paramaters and values

    SoapSerializationEnvelope envelope = new         SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request1);

    //Web method call
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true;

    androidHttpTransport.call(SOAP_ACTION1, envelope);

    //get the response
    SoapPrimitive result= (SoapPrimitive)envelope.getResponse();

    String results = result.toString();
    methodbody.setText( ""+results); 

           }
    catch (Exception e)
    {
    methodbody.setText(e.getMessage());
    e.printStackTrace();
        }
    break;

       }

}
于 2013-01-25T07:58:05.743 回答