SOAP web服务返回不正确的响应



我在本地工作。我在。net中做了一个web服务,它接受用户名和密码并对用户进行身份验证。我的web服务代码是:http://pastebin.com/GQGtKSqq,我的日志显示如下:http://pastebin.com/czs5Fbc3

我的日志显示输出是我的web服务的catch语句的一条语句,它实际上应该在try块中显示语句,即"success"。当我从Android应用程序调用web服务时,我没有得到与我在浏览器中运行web服务时得到的相同的响应。我已经在SQL数据库中存储了用户名和密码,谁能帮助解决我的问题?我的android代码如下:

       package com.demo;
       import org.ksoap2.SoapEnvelope;
       import org.ksoap2.serialization.SoapObject;
       import org.ksoap2.serialization.SoapPrimitive;
       import org.ksoap2.serialization.SoapSerializationEnvelope;  
       import org.ksoap2.transport.AndroidHttpTransport;
       import android.app.Activity;
       import android.app.ProgressDialog;
       import android.os.AsyncTask;
       import android.os.Bundle;
       import android.util.Log;
       import android.view.View;
       import android.view.View.OnClickListener;
       import android.widget.Button;
       import android.widget.EditText;
        public class Login extends Activity {
private static final String SOAP_ACTION = "http://tempuri.org/GetLoginDetails";
private static final String METHOD_NAME = "GetLoginDetails";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://10.0.2.2/testlogin/Service1.asmx";
@Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button signin = (Button) findViewById(R.id.regsubmitbtn);
        signin.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    String user_id;
                    String password;
                        EditText etxt_user = (EditText) findViewById(R.id.usereditlog);
                        user_id = etxt_user.getText().toString();
                        EditText etxt_password = (EditText)  findViewById(R.id.pwdeditlog);
                        password = etxt_password.getText().toString();
                        new LoginTask().execute();
                }
             });
        }

      private class LoginTask extends AsyncTask<Void, Void, Void> {
        String auth = null;
         private final ProgressDialog dialog = new ProgressDialog(
                    Login.this);
          protected void onPreExecute() {
                  this.dialog.setMessage("Logging in...");
                  this.dialog.show();
          }
    protected Void doInBackground(final Void... unused) {
            auth = doLogin("hello", "hello");
            return null; // don't interact with the ui!
    }
    protected void onPostExecute(Void result) {
            if (this.dialog.isShowing()) {
                    this.dialog.dismiss();
            }
        System.out.println(auth);
    }
     }

      private String doLogin(String user_id, String password) {
          SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            request.addProperty("user", user_id);
           request.addProperty("password", password);
              SoapSerializationEnvelope soapenvelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
           soapenvelope.dotNet = true; // Set this variable to true for
          soapenvelope.setOutputSoapObject(request);
    AndroidHttpTransport httptransport = new AndroidHttpTransport(URL);
    try {
            httptransport.call(SOAP_ACTION, soapenvelope);
            SoapPrimitive resultstring = (SoapPrimitive) soapenvelope
                            .getResponse();
            Log.d("Authenticaion", resultstring+"");
            System.out.println(resultstring);
            return resultstring + "";
    } catch (Exception e) {
            e.printStackTrace();
    }
    return "";
         } 
     }

try this:I did like this

// ksoap2 calling wcf
public SoapPrimitive soapPrimitiveData(String tablename,String strBusinessUnit, String strExecutive, String strTerritoryCode,String strUField1) throws IOException,XmlPullParserException {
    SoapPrimitive responsesData = null;
    SoapObject requestData = new SoapObject(NAMESPACE, METHOD_TABLEDATA); // set
    Date date = new Date();
    DateFormat formatter = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
    String strDate = formatter.format(date);
    requestData.addProperty("strBusinessUnit", strBusinessUnit);
    requestData.addProperty("strExecutive", strExecutive);
    requestData.addProperty("strTableName", tablename);
    requestData.addProperty("strDate", strDate);
    requestData.addProperty("strTerritoryCode", strTerritoryCode);
    requestData.addProperty("strUField1", strUField1);
    SoapSerializationEnvelope envelopes = new SoapSerializationEnvelope(SoapEnvelope.VER11); // put all required data into a soap//// envelope
    envelopes.dotNet = true;
    envelopes.setOutputSoapObject(requestData);
    AndroidHttpTransport httpTransport = new AndroidHttpTransport(APPURL);
    httpTransport.debug = true;
    try {
        httpTransport.call(SOAP_ACTION1, envelopes);
        responsesData = (SoapPrimitive) envelopes.getResponse();

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

你的代码是正确的。

在你的'onpostexecute()你必须写下一个活动调用部分…

         @Override
    protected void onPostExecute(Void result) {
        if (this.dialog.isShowing()) {
            this.dialog.dismiss();
        }
        Toast.makeText(DownlaodTableActivity.this,"All The tables Downloaded Successfully",Toast.LENGTH_SHORT).show();

        if(comingFrom.equals("Success")){
            Intent i = new Intent(getBaseContext(), SettingScreenActivity.class);
            View vi = SettingActivityGroup.group.getLocalActivityManager().startActivity("SettingScreenActivity", i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
            SettingActivityGroup.group.replaceView(vi);

        }else{
            Intent showContent = new Intent(getApplicationContext(),MainActivity.class);
            startActivity(showContent);
        }
    }

最新更新