-1

我有这段代码可以在 localhost 上调用 donNet 网络服务。Web 服务接受 5 个值并返回一个字符串。我接受了这个错误:错误 HTTP 请求失败,HTTP 状态 400。这里有什么问题?

公共类 MainActivity 扩展 Activity {

private final String NAMESPACE = "http://tempuri.org/";
  private final String URL = "http://10.0.2.2:6371/Service1.asmx";


         int IDocID;
         String SName,SDate,STime,SReason;
         TextView txt;
         private PropertyInfo AppDoctor,AppDate,AppTime,AppName,AppReason;

@Override
   protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button sent=(Button)findViewById(R.id.button1);


    txt=(TextView)findViewById(R.id.textView6);

    sent.setOnClickListener(new View.OnClickListener()
  {
        public void onClick(View v)
         {

            EditText DocID=(EditText)findViewById(R.id.editTextDoc);
            IDocID = Integer.parseInt(DocID.getText().toString());
            EditText Date= (EditText)findViewById(R.id.editTextDate);
            SDate = Date.getText().toString();
            EditText Time=(EditText)findViewById(R.id.editTextTime);
            STime = Time.getText().toString();
            EditText Name=(EditText)findViewById(R.id.editTextName);
            SName = Name.getText().toString();
            EditText Reason=(EditText)findViewById(R.id.editTextReason);
            SReason = Reason.getText().toString();



            new InsertTask().execute();

         }
    });
    }

private String doInsert(String SName,String SDate,String STime,String SReason, int IDocID )  {   

       String result="";
       final String SOAP_ACTION = "http://tempuri.org/InsertAppointment";
       final String METHOD_NAME = "InsertAppointment";     
       SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);


         request.addProperty("AppDoctor",IDocID);
         request.addProperty("AppDate",SDate);
         request.addProperty("AppTime",STime);
         request.addProperty("AppName",SName);
         request.addProperty("AppReason",SReason);

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

      envelope.setOutputSoapObject(request);


       System.out.println(request);
       System.out.println(envelope.toString());
       HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);


       try {

               androidHttpTransport.call(SOAP_ACTION, envelope);
               SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

               Log.i("myApp", response.toString());
               /

                       if(response != null)
           {
                           String resp= response.toString();
                           result = resp;
                           txt.setText(resp);
           }

       }catch(SocketException ex)
       {
           Log.e("Error : " , "Error on soapPrimitiveData() " + ex.getMessage());
           ex.printStackTrace();
           txt.setText(ex.toString());
       }
       catch (Exception e) {
           Log.e("Error : " , "Error on soapPrimitiveData() " + e.getMessage());
               e.printStackTrace();
       }
       return result;

       }

private class InsertTask extends AsyncTask<Void, Void, Void> {

    private final ProgressDialog dialog = new ProgressDialog(MainActivity.this);

    protected void onPreExecute() {

            this.dialog.setMessage("Logging in...");
            this.dialog.show();

    }


    protected Void doInBackground(final Void... unused) {

        String auth=doInsert( SName, SDate, STime, SReason,  IDocID);

        System.out.println(auth);

        return null;// don't interact with the ui!
    }


    protected void onPostExecute(Void result) {


            if (this.dialog.isShowing()) {
            this.dialog.dismiss();
        }         
      }

    } 
4

1 回答 1

0

尝试将“”添加到您的 SOAP_ACTION:

final String SOAP_ACTION = "\"http://tempuri.org/InsertAppointment\"";
于 2013-05-27T00:08:27.947 回答