0

これは私のプリミティブ Web サービスです。

@Override
    public boolean LogOn(String UserName, String Password) {

            String username = "";
            String password = "";
        if (UserName != null) {
            username = UserName;
        }
        if (Password != null) {
            password = Password;
        }
        System.out.println("username is"+username);
        System.out.println("password is"+password);
        //test parameters
        if (username.equals("admin") && password.equals("admin")) {
            return true;
        } else {
            return false;
        }

    }

Android 上のこのクライアント:

private static final String METHOD_NAME = "LogOn";
private static final String NAMESPACE = "http://calculator.me.org/";
private static final String URL = "http://10.0.2.2:8080/logon/WebServiceImplService?wsdl";


@Override
    protected Integer doInBackground(String... params) {
        // TODO Auto-generated method stub
         try 
          {
             SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
             //Add the input variables for the method 
             request.addProperty("username", "admin");
             request.addProperty("password","admin");
             SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
             envelope.setOutputSoapObject(request);
             System.setProperty("http.keepAlive", "false");
             HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
             androidHttpTransport.debug=true;
             androidHttpTransport.call(getSoapAction(METHOD_NAME), envelope);
             SoapObject result = (SoapObject) envelope.bodyIn;
             //get response from web server
             String d =result.getProperty("return").toString();
            // Logging the raw request and response (for debugging purposes)
             Log.d(TAG, "HTTP REQUEST:\n" + androidHttpTransport.requestDump);
             Log.d(TAG, "HTTP RESPONSE:\n" + androidHttpTransport.responseDump);
             Log.i(TAG,"response from service:"+d);
             if(d.equals("true"))
             {
                 //The result will be here, use it wisely :)
                 return 1;
             }

             else
                 return 0;
          } catch (Exception e) {
              Log.e(TAG,"doInBackground failed"+e);
              e.printStackTrace();
              return 0;

          }

    }

Web サービスを手動でテストしているときは、Web サービスをログに記録します。

INFO:   username isadmin
INFO:   password isadmin

Androidクライアントからログインしようとすると、次のログが表示されます:

INFO:   username is
INFO:   password is

nullpointer チェックを削除すると、Web サービスで NullPointerException が発生します。Android クライアントからのログ:

11-12 02:29:55.081: D/SmsSender:LogOnAsync(1878): HTTP REQUEST:
11-12 02:29:55.081: D/SmsSender:LogOnAsync(1878): <v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header /><v:Body><n0:LogOn id="o0" c:root="1" xmlns:n0="http://calculator.me.org/"><username i:type="d:string">admin</username><password i:type="d:string">admin</password></n0:LogOn></v:Body></v:Envelope>
11-12 02:29:55.081: D/SmsSender:LogOnAsync(1878): HTTP RESPONSE:
11-12 02:29:55.081: D/SmsSender:LogOnAsync(1878): <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:LogOnResponse xmlns:ns2="http://calculator.me.org/"><return>false</return></ns2:LogOnResponse></S:Body></S:Envelope>
11-12 02:29:55.081: I/SmsSender:LogOnAsync(1878): response from service:false

どうしたの?

4

1 に答える 1