2012-07-11 5 views
2

KSOAP를 사용하여 웹 서비스를 사용하여 데이터베이스에 저장 될 세부 정보를 보내고 있습니다. Visual Studio를 사용하여 웹 서비스를 만들었습니다. 웹 서비스가 제대로 작동합니다. 세부 사항이 데이터베이스에 삽입되면 문자열이 리턴됩니다. 문제는이 문자열이 비어있는 것입니다. 응답을받는 방식에 문제가있을 수 있습니다. 나는 오랫동안 잘못된 것을 찾아 내려고 노력해왔다. 귀하의 웹 서비스가 String을 반환웹 서비스에서받은 응답이 null입니다.

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) { 
    } 

    } 
    } 

enter image description here

+0

도움이되기를 바랍니다 SOAP_ACTION. 'SOAP_ACTION'은'http : // tempuri.org/register'입니다. 'http : //10.0.2.2 : 58076/WebSite1/Service.asmx'이어야합니다. – adatapost

+0

동일하게 시도했습니다. –

+0

먼저 SOAPUI 도구를 사용하여 SOAP 응답이 원하는대로 나오는지 확인하십시오. – YuDroid

답변

3

도와주세요. 문제를 해결하려면이 옵션을 사용해보십시오

  Object result = envelope.getResponse(); 

유형 바이트의 당신의 웹 서비스 반환 값은 [], 당신이 할 수있는 경우 :

  SoapObject response=(SoapObject)envelope.bodyIn; 

당신은의 값을 변경해야 할 것이

+0

답변을 100 번 투표 할 수 있다면 ... 감사합니다 !!! –

관련 문제