java.io.IOException异常:HTTP请求失败,HTTP状态:500的Andr​​oid使用WCF为Android

问题描述:

我一直在试图摆脱WCF点网web服务数据响应,但不能得到正确的回应。从2天后,在连接过程中的WebServices流汗这个错误。

I have been trying to get data response from wcf dot net webservices but could not get properly response. From 2 days, gettting this error during connect webservices.

我也查的 SoapEnvelope.VER11 的,但不能得到数据。

I also check SoapEnvelope.VER11 but could not get data.

public class MainActivity extends Activity {

private static final String METHOD_NAME = "SayHello";

private static final String NAMESPACE = "http://tempuri.org/IWFPService/";
private static final String URL = "http://*****.svc";

private static final String SOAP_ACTION = NAMESPACE+METHOD_NAME;
private TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    textView = (TextView) findViewById(R.id.test);
    AsyncTaskRunner runner = new AsyncTaskRunner();
    runner.execute();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
private class AsyncTaskRunner extends AsyncTask<String, String, String> {

    private String resp;
    @Override
    protected String doInBackground(String... params) {
        publishProgress("Loading contents..."); // Calls onProgressUpdate()
        try {
            // SoapEnvelop.VER11 is SOAP Version 1.1 constant
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER12);
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            //request.addProperty("TestNumber", 12);
            //bodyOut is the body object to be sent out with this envelope
            envelope.bodyOut = request;
            envelope.dotNet = true;
            Log.e(SOAP_ACTION, "-->URL>"+URL);
            Log.e(SOAP_ACTION, "-->METHOD_NAME>"+METHOD_NAME);
            Log.e(SOAP_ACTION, "-->SOAP_ACTION>"+SOAP_ACTION);
            Log.e(SOAP_ACTION, "-->envelope>"+envelope);
             Log.v("", "=========== Request : " + request);
            HttpTransportSE transport = new HttpTransportSE(URL);
            try {
                transport.call(SOAP_ACTION, envelope);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                e.printStackTrace();
            }
            //bodyIn is the body object received with this envelope
            if (envelope.bodyIn != null) {
                //getProperty() Returns a specific property at a certain index.
                SoapPrimitive resultSOAP = (SoapPrimitive) ((SoapObject) envelope.bodyIn)
                        .getProperty(0);
                resp=resultSOAP.toString();
                Log.e(SOAP_ACTION, "-->>"+resp);
            }
            Log.e(SOAP_ACTION, "<<<-->>"+resp);
        } catch (Exception e) {
            e.printStackTrace();
            resp = e.getMessage();
        }
        return resp;
    }

    /**
     * 
     * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
     */
    @Override
    protected void onPostExecute(String result) {
        // execution of result of Long time consuming operation
        // In this example it is the return value from the web service
        textView.setText(resp);
    }

    /**
     * 
     * @see android.os.AsyncTask#onPreExecute()
     */
    @Override
    protected void onPreExecute() {
        // Things to be done before execution of long running operation. For
        // example showing ProgessDialog
    }

    /**
     * 
     * @see android.os.AsyncTask#onProgressUpdate(Progress[])
     */
    @Override
    protected void onProgressUpdate(String... text) {
        textView.setText(text[0]);
        // Things to be done while execution of long running operation is in
        // progress. For example updating ProgessDialog
    }
}

}

我绿色已logcat的:

I have logcat in green color:

04-16 12:10:41.363: E/http://tempuri.org/IWFPService/SayHello(22684): -->URL>http://192.168.169.133/WFPeWin2/content/WFPService.svc
04-16 12:10:41.363: E/http://tempuri.org/IWFPService/SayHello(22684): -->METHOD_NAME>SayHello
04-16 12:10:41.363: E/http://tempuri.org/IWFPService/SayHello(22684): -->SOAP_ACTION>http://tempuri.org/IWFPService/SayHello
04-16 12:10:41.363: E/http://tempuri.org/IWFPService/SayHello(22684): -->envelope>org.ksoap2.serialization.SoapSerializationEnvelope@4212da18
04-16 12:10:41.363: V/(22684): =========== Request : SayHello{}
04-16 12:10:41.598: W/System.err(22684): java.io.IOException: HTTP request failed, HTTP status: 500
04-16 12:10:41.598: W/System.err(22684):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:195)
04-16 12:10:41.598: W/System.err(22684):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
04-16 12:10:41.598: W/System.err(22684):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:111)
04-16 12:10:41.598: W/System.err(22684):    at com.example.samplews.MainActivity$AsyncTaskRunner.doInBackground(MainActivity.java:67)
04-16 12:10:41.598: W/System.err(22684):    at com.example.samplews.MainActivity$AsyncTaskRunner.doInBackground(MainActivity.java:1)
04-16 12:10:41.598: W/System.err(22684):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-16 12:10:41.598: W/System.err(22684):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-16 12:10:41.598: W/System.err(22684):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-16 12:10:41.598: W/System.err(22684):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-16 12:10:41.598: W/System.err(22684):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-16 12:10:41.598: W/System.err(22684):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-16 12:10:41.598: W/System.err(22684):    at java.lang.Thread.run(Thread.java:856)
04-16 12:10:41.598: E/http://tempuri.org/IWFPService/SayHello(22684): <<<-->>null

什么是错我的code,任何想法??

What is wrong with my code, any idea??

嗯.. HTTP 500内部服务器错误,所以你应该检查服务器正在与SOAPUI或其他一些工具对于初学者。然后确保可以从该设备访问的网址(在本例中IP号码),然后开始调试ksaop电话。

Well.. HTTP 500 is an internal server error so you should probably check the server is working with SOAPUI or some other tool for starters. Then make sure that you can reach the URL (IP number in this case) from the device and then start debugging the ksaop call.