Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从web服务收到的响应为空_Java_Android_Eclipse_Web Services_Ksoap2 - Fatal编程技术网

Java 从web服务收到的响应为空

Java 从web服务收到的响应为空,java,android,eclipse,web-services,ksoap2,Java,Android,Eclipse,Web Services,Ksoap2,我正在使用KSOAP的web服务发送要存储在数据库中的详细信息。我已经使用VisualStudio创建了web服务。web服务运行良好。将详细信息插入数据库后,将返回一个字符串。问题是这个字符串是空的,可能是我得到响应的方式有问题。很长时间以来,我一直在努力找出问题所在。请帮忙 public class Registration extends Activity{ private static final String SOAP_ACTION = "http://tempuri.org/regi

我正在使用KSOAP的web服务发送要存储在数据库中的详细信息。我已经使用VisualStudio创建了web服务。web服务运行良好。将详细信息插入数据库后,将返回一个字符串。问题是这个字符串是空的,可能是我得到响应的方式有问题。很长时间以来,我一直在努力找出问题所在。请帮忙

public class Registration extends Activity{
private static final String SOAP_ACTION = "http://tempuri.org/register";
private static final String OPERATION_NAME = "register";
private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ADDRESS = "http://10.0.2.2:58076/WebSite1/Service.asmx";
Button sqlRegister, sqlView;

EditText  sqlFirstName,sqlLastName,sqlEmail,sqlMobileNumber,sqlCurrentLocation,sqlUsername,sqlPassword;

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.registration);
sqlFirstName = (EditText) findViewById(R.id.etFname);
sqlLastName = (EditText) findViewById(R.id.etLname);
sqlEmail = (EditText) findViewById(R.id.etEmail);
sqlMobileNumber = (EditText) findViewById(R.id.etPhone);
sqlCurrentLocation = (EditText) findViewById(R.id.etCurrentLoc);

sqlUsername = (EditText) findViewById(R.id.etUsername);
sqlPassword = (EditText) findViewById(R.id.etPwd);

sqlRegister = (Button) findViewById(R.id.bRegister);
sqlRegister.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        switch (v.getId()){
        case R.id.bRegister:
        new LongOperation().execute("");
        break;
      }
     }
    });
}

private class LongOperation extends AsyncTask<String, Void, String> {

    @Override
    protected String doInBackground(String... params) {
         String firstname = sqlFirstName.getText().toString();
         String lastname = sqlLastName.getText().toString();
         String emailadd = sqlEmail.getText().toString();
         String number = sqlMobileNumber.getText().toString();
         String loc = sqlCurrentLocation.getText().toString();
         String uname = sqlUsername.getText().toString();
         String pwd = sqlPassword.getText().toString();

         SoapObject Request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
         Request.addProperty("fname", String.valueOf(firstname));
         Request.addProperty("lname", String.valueOf(lastname));
         Request.addProperty("email", String.valueOf(emailadd));
         Request.addProperty("num", String.valueOf(number));
         Request.addProperty("loc", String.valueOf(loc));
         Request.addProperty("username", String.valueOf(uname));
         Request.addProperty("password", String.valueOf(pwd));

         SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
         envelope.dotNet = true;
         envelope.setOutputSoapObject(Request);
         HttpTransportSE httpTransport  = new HttpTransportSE(SOAP_ADDRESS);
         Log.d("work","work");
         try
         {
            httpTransport.call(SOAP_ACTION, envelope);
             SoapObject response = (SoapObject)envelope.getResponse();
             String result =  response.getProperty(0).toString();
             Log.d("res",result);
             if(result.equals("reg"))
             {
                 Log.d("reg","reg");
                 return "Registered";
             }
             else
             {
                 Log.d("no","no");
                 return "Not Registered";
             }
         }catch(Exception e){
            e.printStackTrace();
        }
         return null;

    }      

    @Override
    protected void onPostExecute(String result) {
        Log.d("tag","onpost");
        if(result!=null)
        {

            if(result.equals("Registered"))
                {
                    Toast.makeText(Registration.this, "You have been registered Successfully", Toast.LENGTH_LONG).show();
                }
            else if(result.equals("Not Registered"))
                {
                    Toast.makeText(Registration.this, "Try Again", Toast.LENGTH_LONG).show();
                }
        }
        else
        {
            Toast.makeText(Registration.this, "Somethings wrong", Toast.LENGTH_LONG).show(); ///This is what gets printed on screen
        }
    }

    @Override
    protected void onPreExecute() {
    }

    @Override
    protected void onProgressUpdate(Void... values) {
    }

    }   
  }
公共类注册扩展活动{
私有静态最终字符串SOAP_ACTION=”http://tempuri.org/register";
私有静态最终字符串操作\u NAME=“register”;
私有静态最终字符串WSDL\u TARGET\u NAMESPACE=”http://tempuri.org/";
私有静态最终字符串SOAP_地址=”http://10.0.2.2:58076/WebSite1/Service.asmx";
按钮sqlRegister,sqlView;
EditText sqlFirstName、sqlLastName、sqlEmail、sqlMobileNumber、sqlCurrentLocation、sqlUsername、sqlPassword;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.registration);
sqlFirstName=(EditText)findViewById(R.id.etFname);
sqlLastName=(EditText)findViewById(R.id.etLname);
sqlEmail=(EditText)findViewById(R.id.etEmail);
sqlMobileNumber=(EditText)findViewById(R.id.etPhone);
sqlCurrentLocation=(EditText)findViewById(R.id.etCurrentLoc);
sqlUsername=(EditText)findViewById(R.id.etUsername);
sqlPassword=(EditText)findViewById(R.id.etPwd);
sqlRegister=(按钮)findViewById(R.id.bRegister);
sqlRegister.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
开关(v.getId()){
案例R.id.bRegister:
新建LongOperation()。执行(“”);
打破
}
}
});
}
私有类LongOperation扩展了异步任务{
@凌驾
受保护的字符串doInBackground(字符串…参数){
String firstname=sqlFirstName.getText().toString();
字符串lastname=sqlLastName.getText().toString();
字符串emailadd=sqlEmail.getText().toString();
字符串编号=sqlMobileNumber.getText().toString();
字符串loc=sqlCurrentLocation.getText().toString();
字符串uname=sqlUsername.getText().toString();
字符串pwd=sqlPassword.getText().toString();
SoapObject请求=新的SoapObject(WSDL\u目标\u命名空间、操作\u名称);
Request.addProperty(“fname”,String.valueOf(firstname));
Request.addProperty(“lname”,String.valueOf(lastname));
Request.addProperty(“email”,String.valueOf(emailadd));
Request.addProperty(“num”,String.valueOf(number));
Request.addProperty(“loc”,String.valueOf(loc));
Request.addProperty(“用户名”,String.valueOf(uname));
Request.addProperty(“密码”,String.valueOf(pwd));
SoapSerializationEnvelope=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(请求);
HttpTransportSE httpTransport=新的HttpTransportSE(SOAP\U地址);
日志d(“工作”、“工作”);
尝试
{
调用(SOAP_操作,信封);
SoapObject响应=(SoapObject)信封.getResponse();
字符串结果=response.getProperty(0.toString();
Log.d(“res”,结果);
如果(结果等于(“reg”))
{
日志d(“注册”、“注册”);
返回“已注册”;
}
其他的
{
日志d(“否”、“否”);
返回“未注册”;
}
}捕获(例外e){
e、 printStackTrace();
}
返回null;
}      
@凌驾
受保护的void onPostExecute(字符串结果){
Log.d(“标签”、“on post”);
如果(结果!=null)
{
如果(结果等于(“注册”))
{
Toast.makeText(Registration.this,“您已成功注册”,Toast.LENGTH_LONG.show();
}
else if(结果等于(“未注册”))
{
Toast.makeText(Registration.this,“重试”,Toast.LENGTH_LONG.show();
}
}
其他的
{
Toast.makeText(Registration.this,“something short”,Toast.LENGTH_LONG.show();///这是屏幕上打印的内容
}
}
@凌驾
受保护的void onPreExecute(){
}
@凌驾
受保护的void onProgressUpdate(void…值){
}
}   
}

您的Web服务正在返回一个
字符串。
试着用这个来解决你的问题

          Object result = envelope.getResponse();
当webservice返回byte[]类型的值时,可以执行以下操作:

          SoapObject response=(SoapObject)envelope.bodyIn;

希望这会有所帮助

您必须改变SOAP\u操作的价值。
SOAP\u操作
http://tempuri.org/register
。它应该是
http://10.0.2.2:58076/WebSite1/Service.asmx
首先使用SOAPUI工具,查看您的SOAP响应是否如您所愿。。