예제 #1
0
  /**
   * Call.
   *
   * @param url the url
   * @param nameSpace the name space
   * @param methodName the method name
   * @param Params the params
   * @param listener the listener
   */
  public void call(
      final String url,
      final String nameSpace,
      final String methodName,
      AbSoapParams Params,
      final AbSoapListener listener) {
    this.mParams = Params;

    if (!AbAppUtil.isNetworkAvailable(mContext)) {
      listener.sendFailureMessage(
          AbHttpStatus.CONNECT_FAILURE_CODE,
          AbAppConfig.CONNECT_EXCEPTION,
          new AbAppException(AbAppConfig.CONNECT_EXCEPTION));
      return;
    }

    listener.sendStartMessage();

    mExecutorService.execute(
        new Runnable() {
          @Override
          public void run() {
            try {
              doCall(url, nameSpace, methodName, mParams, listener);
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        });
  }
예제 #2
0
  /**
   * Do call.
   *
   * @param url the url
   * @param nameSpace the name space
   * @param methodName the method name
   * @param params the params
   * @param listener the listener
   */
  public void doCall(
      String url,
      String nameSpace,
      String methodName,
      AbSoapParams params,
      AbSoapListener listener) {
    try {
      SoapObject request = new SoapObject(nameSpace, methodName);
      // 传递参数
      List<BasicNameValuePair> paramsList = params.getParamsList();
      for (NameValuePair nameValuePair : paramsList) {
        request.addProperty(nameValuePair.getName(), nameValuePair.getValue());
      }
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
      envelope.bodyOut = request;
      envelope.dotNet = mDotNet;
      envelope.setOutputSoapObject(request);
      HttpTransportSE httpTransportSE = new HttpTransportSE(url, mTimeout);
      httpTransportSE.debug = true;

      AbLogUtil.d(AbSoapClient.class, "--call--");
      httpTransportSE.call(nameSpace + methodName, envelope);
      Object object = envelope.bodyIn;
      if (object instanceof SoapObject) {
        SoapObject bodyIn = (SoapObject) envelope.bodyIn;
        if (bodyIn != null) {
          listener.sendSuccessMessage(AbHttpStatus.SUCCESS_CODE, bodyIn);
        }
      } else if (object instanceof SoapFault) {
        SoapFault fault = (SoapFault) envelope.bodyIn;
        if (fault != null) {
          listener.sendFailureMessage(AbHttpStatus.SERVER_FAILURE_CODE, fault);
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
      listener.sendFailureMessage(
          AbHttpStatus.UNTREATED_CODE,
          AbAppConfig.UNTREATED_EXCEPTION,
          new AbAppException(AbAppConfig.UNTREATED_EXCEPTION));
    }
  }