1

json 文字列を送信しようとしていますが、WebService を呼び出すと、文字列ではなく null パラメーターが送信されます。デバッグに行くと、soapObject プロパティで私の json を確認できます。しかし、私のwebServiceに入れました.Androidアプリから呼び出すと、彼は常にnullを返します

if (json.Equals(null)) {
    return "null";
}

try {
    return json;
    root = JObject.Parse(json);
} catch (Exception e) {
    return e.StackTrace; 
}
return "parseok";

これが私が使用しているコードです。

 public class OpcoesActivity extends Activity implements OnClickListener {
      private String cpf;
      private String senha;
      private PontosUsuarioDAO pdao = new PontosUsuarioDAO(this);
      @Override
      protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.opcoeslayout);

           cpf = getIntent().getStringExtra("cpf");
           senha = getIntent().getStringExtra("senha");
           Button importar = (Button) findViewById(R.id.bt_importar);
           importar.setOnClickListener(this);
           Button exportar = (Button) findViewById(R.id.bt_exportar);
           exportar.setOnClickListener(this);
      }

      public void onClick(View v) {

           switch (v.getId()) {
                case R.id.bt_importar:
                     Intent i = new Intent(this, SincronizarActivity.class);
                     i.putExtra("cpf", cpf);
                     i.putExtra("senha", senha);
                     startActivity(i);
                     break;
                case R.id.bt_exportar:
                     new Thread(new Runnable() {
                          public void run() {
                               Gson gson = new Gson();
                               final String json = gson.toJson(pdao.exportaPontosUsuario(cpf));
                               ExportarDados exp = new ExportarDados("{\"teste\":\"java\"}");
                               String b = exp.ExportaDadosUser();
                          }
                     }).start();
                     break;
                }
           }
      }

そして、これがエクスポートするクラスです

 public class ExportarDados {
      private static final String SOAP_ACTION = "http://serv.lageo.ufpr.br/EnviaPontosUsuario";
      private static final String METHOD_NAME = "EnviaPontosUsuario";
      private static final String NAMESPACE = "http://serv.lageo.ufpr.br/";
      private static final String URL = "http://200.17.203.150/Caderneta/Sincronizar.asmx";
      private String json;
      private SoapObject soapObject;
      private String result = ""; 

      public ExportarDados(String json) {
           this.json = json;
      }

      public String ExportaDadosUser() {
           String e2;
           try {
                soapObject = new SoapObject(NAMESPACE, METHOD_NAME);
                soapObject.addProperty("json", json);
                SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                soapEnvelope.dotNet = true;
                soapEnvelope.setOutputSoapObject(soapObject);

                HttpTransportSE ht = new HttpTransportSE(URL);
                ht.call(SOAP_ACTION, soapEnvelope);
                SoapPrimitive resultString = (SoapPrimitive) soapEnvelope.getResponse();
                result = resultString.toString();
           } catch(Exception e) {
                e.printStackTrace();
           }

           return result;
      }
 }
4

1 に答える 1