3

我正在尝试从 Android 调用 .asmx 网络服务。下面你可以看到我的代码。当我将它用于另一个 Web 服务时它正在工作,但它不适用于我需要使用的一个。问题是“java.io.IOException:HTTP 请求失败,HTTP 状态:500”异常。首先,我假设问题出在 Web 服务端。但是,当我尝试使用 Devexpress 和 .NET 时,它会起作用。

当我删除“contentType:”application/json; 时,我试图从 Devexpress 得到同样的错误。charset=utf-8"," 行。

注意:Web 服务定义没有错误。

私有类 KullaniciServiceAsync 扩展 AsyncTask {

    protected void onPreExecute(){
        Toast.makeText(getApplicationContext(), "Kullanici Bilgileri Alınıyor...", Toast.LENGTH_SHORT).show();
    }
    @Override
    protected KullaniciBilgisiGetir doInBackground(String... Str) {
        try {
            //ArrayList<HeaderProperty> headerProperty = new ArrayList<HeaderProperty>();  
            //headerProperty.add(new HeaderProperty("Content-Type", "application/json; charset=utf-8")); 
            k = new KullaniciBilgisiGetir();    
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            request.addProperty("UserId","1234567890");
            request.addProperty("Password",Pass);
            request.addProperty("Kod",Kod);
            request.addProperty("Sifre",Sifre);
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            Log.e("Request",request.toString());
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.debug = true;
            try{
                 androidHttpTransport.call(SOAP_ACTION, envelope);
                 SoapObject response = (SoapObject) envelope.getResponse();
                 if (response.hasProperty("KResult")) {
                    if (response.getPropertyAsString("KResult") == null) {
                      k.setKullaniciRespond(null);
                    } else {
                      k.setKullaniciRespond(response.getPropertyAsString("KResult"));
                    }
                 }

             }catch(Exception e){
                 Log.e("httpTRYCATCH", e.toString());
             }
        } catch (Exception e) {
          Log.e("ilkTRY",e.toString());
        }              
        return k;
    }

    protected void onPostExecute(KullaniciBilgisiGetir e){
        txt1.setText("ResponseText   ->" + e.getKullaniciRespond());
        //txt2.setText("bu "+e.getResponse());
        //txt3.setText("Count "+count);
    }

}
4

2 回答 2

1

java.io.IOEXCEPTION

Signals that an I/O exception of some sort has occurred. This class is the general class of exceptions produced by failed or interrupted I/O operations.

The Web server encountered an unexpected condition that prevented it from fulfilling the request by the client for access to the requested URL.

May be something is wrong at the server end, but the server can not be more specific about the error condition in its response.

therefore it returns it as a error code 500 which means there was an error at server end.

chances of getting this error might be

  1. The inputs or values that require to be passed for the method on server side and in your code side are different.
  2. May be your inputs were right but at some point the server failed to process output at his end and given you the response 500

How can it be resolved?

You will have to ask system administrator to check the error log at his end(if any log is used on their side).If the error is logged you will know the exact reason.

于 2013-04-29T12:51:34.970 回答
0

请检查属性名称是否与 Web 服务参数相同。

例如;

request.addProperty("UserId","1234567890");

您的参数名称是 Web 服务上的 UserId 吗?

您也可以按照本教程进行操作:Android Programlama – .Net Web Service Kullanımı

于 2013-09-30T00:22:59.390 回答