Невозможно получить ответ от сервера после создания простого входа в систему - PullRequest
0 голосов
/ 19 мая 2019

Пытается создать активность входа, но не получает никакого ответа.Я использовал все различные типы кодов, предложенных в потоке укладки, но не удалось.

Веб-служба: это веб-служба, с которой я пытаюсь получить данные.

\\Web Service used to fetch data

    POST /Service.asmx HTTP/1.1
    Host: 192.168.1.100
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://tempuri.org/Login"

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <Login xmlns="http://tempuri.org/">
          <Name>string</Name>
          <Password>string</Password>
        </Login>
      </soap:Body>
    </soap:Envelope>
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length


<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <LoginResponse xmlns="http://tempuri.org/">
          <LoginResult>string</LoginResult>
        </LoginResponse>
      </soap:Body>
    </soap:Envelope>
Login Activity: 

    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;

    import org.ksoap2.SoapEnvelope;
    import org.ksoap2.serialization.PropertyInfo;
    import org.ksoap2.serialization.SoapObject;
    import org.ksoap2.serialization.SoapPrimitive;
    import org.ksoap2.serialization.SoapSerializationEnvelope;
    import org.ksoap2.transport.HttpTransportSE;

    public class Login extends AppCompatActivity {

        private final String NAMESPACE = "http://tempuri.org";
        private final String URL = "http://192.168.1.100/Service.asmx?wsdl";
        private final String SOAP_ACTION = "http://tempuri.org/Login";
        private final String METHOD_NAME = "Login";

        /* Called when the activity is first created. */

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

            Button login = (Button) findViewById(R.id.button_login);
            login.setOnClickListener(new View.OnClickListener(){

                @Override
                public void onClick(View v) {
                    loginAction();
                }
            });
        }

        private void loginAction() {
//Toast.makeText(this, "Button Clicked", Toast.LENGTH_SHORT).show();
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            EditText userName = (EditText) findViewById(R.id.editText_user);
            String user_Name = userName.getText().toString();
            EditText userPassword = (EditText) findViewById(R.id.editText_password);
            String user_Password = userPassword.getText().toString();

//Pass value for userName variable of the web service
            PropertyInfo unameProp = new PropertyInfo();
            unameProp.setName("Name");//Define the variable name in the web service method
            unameProp.setValue(user_Name);//set value for userName variable
            unameProp.setType(String.class);//Define the type of the variable
            request.addProperty(unameProp);//Pass properties to the variable

//Pass value for userName variable of the web service
            PropertyInfo passwordProp = new PropertyInfo();
            passwordProp.setName("Password");//Define the variable name in the web service method
            passwordProp.setValue(user_Password);//set value for userName variable
            passwordProp.setType(String.class);//Define the type of the variable
            request.addProperty(passwordProp);//Pass properties to the variable

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);


            try {
                androidHttpTransport.call(SOAP_ACTION, envelope);
                SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
                String LoginResponse = response.toString();

                TextView LoginResult = (TextView) findViewById(R.id.textView5);
                LoginResult.setText(response.toString());

                if (LoginResponse.equals("True")) {
                    Toast.makeText(this, "Login Successful", Toast.LENGTH_SHORT).show();

                    Intent i = new Intent(getApplicationContext(), User.class);
                    startActivity(i);
                } else {
                    Toast.makeText(this, "Try Again", Toast.LENGTH_SHORT).show();
                }
            } catch (Exception c){

            }
        }
    }


Я новичок в Android и успешно выполнил простую операцию входа в систему, но не смог получить указанные ниже данные.

"IsValidUser":"True",
"UserId":"<id>",
"DisplayName":"<Name>",
"RoleId":<Role Id>,
"RoleName":"<Role Name>"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...