0

Android で ksoap2 を使用して .net ベースの WCF サービスを呼び出そうとしています。httptransport の呼び出し中に次のエラーが発生しました。

これが私のコードです:

public class MainActivity extends Activity {
EditText t1,t2;
Button b1;
TextView result;

private static final String NAMESPACE="http://tempuri.org/";
private static final String METHOD_NAME="AddEmployee";
private static final String URL="http://10.32.4.24/Android/AndroidBus.svc";
private static final String SOAP_ACTION="http://tempuri.org/IAndroidBus/AddEmployee";
SoapObject request=new SoapObject(NAMESPACE,METHOD_NAME);
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        t1=(EditText)findViewById(R.id.editText1);
        t2=(EditText)findViewById(R.id.editText2);
        result=(TextView)findViewById(R.id.textView1);
        b1=(Button)findViewById(R.id.button1);
        b1.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View arg0) {
            PropertyInfo pi=new PropertyInfo();
            pi.setValue("abc");
            pi.setName("value1");
            //pi.type=PropertyInfo.STRING_CLASS;
            SoapObject Request=new SoapObject(NAMESPACE,METHOD_NAME);

            Request.addProperty(pi);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
            envelope.dotNet=true;
            envelope.setOutputSoapObject(Request);

             new servicecall(envelope).execute();



            }

        });
    }

    public class servicecall extends AsyncTask<String,Void,String>
    {
        String res;
        SoapSerializationEnvelope envelope;
        public servicecall(SoapSerializationEnvelope envelope)
        {
            this.envelope=envelope;
        }

        @Override
        protected String doInBackground(String... arg0) {
            HttpTransportSE ht=new HttpTransportSE(URL);
            ht.debug=true;  
            try
            {
                Log.d("WEBSERVICE","Calling");
               ht.call(SOAP_ACTION,envelope);
              SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
              String dump=ht.responseDump.toString();
              System.out.println("dumppp"+dump);
               Log.d("Tag","Response"+response);
               res=response.toString();

            }
            catch(Exception e)
            {
                e.printStackTrace();

            }

            return res;
        }

        protected void onPostExecute(String res) {
            super.onPostExecute(res);
            result.setText("completed");

    }
    }

これは私が得ているエラーです:

11-08 15:00:24.421: W/System.err(767): java.lang.NullPointerException
11-08 15:00:24.451: W/System.err(767):  at org.ksoap2.transport.ServiceConnectionSE.getResponseProperties(ServiceConnectionSE.java:85)
11-08 15:00:24.473: W/System.err(767):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:187)
11-08 15:00:24.483: W/System.err(767):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:114)
11-08 15:00:24.504: W/System.err(767):  at com.example.androidservice.MainActivity$servicecall.doInBackground(MainActivity.java:81)
11-08 15:00:24.522: W/System.err(767):  at com.example.androidservice.MainActivity$servicecall.doInBackground(MainActivity.java:1)
11-08 15:00:24.533: W/System.err(767):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
11-08 15:00:24.541: W/System.err(767):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-08 15:00:24.661: W/System.err(767):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-08 15:00:24.671: W/System.err(767):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
11-08 15:00:24.685: W/System.err(767):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-08 15:00:24.711: W/System.err(767):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-08 15:00:24.722: W/System.err(767):  at java.lang.Thread.run(Thread.java:856)
4

3 に答える 3

0

受け取った応答が null でないことを確認してください。

    SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
    if(null==response){ 
        return;
    }
    else{
        //continue processing
    }

動作する KSOAP コード

于 2012-11-08T10:22:35.613 に答える
0

この記事を読んでください。あなたがしなければならないことをすべて説明しています。コードを再発行できます。できます。http://insightforfuture.blogspot.com/2012/02/accessing-apache-axis2-web-service_24.html

于 2012-11-10T03:57:52.920 に答える
0

ボタンのクリック時にバックグラウンド サービスを呼び出し、doInBackground メソッドのコードを以下のように変更するだけです。

                  SoapObject request = new SoapObject(NAMESPACE, methode);
        // Add the input required by web service

        request.addProperty("abc", value1);



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

        envelope.setOutputSoapObject(request);

        HttpTransportSE httpTransport = new HttpTransportSE(URL);

        httpTransport.call(Action, envelope);

        Object response = envelope.getResponse();

        Log.v("Responce", "Responce:::" + response.toString());

        result = response.toString();
于 2012-11-08T09:56:13.160 に答える