Android中的WebService出错。对象引用未设置为对象的实例

时间:2016-12-02 14:53:13

标签: java android web-services soap android-ksoap2

这个问题可能有点长。我试图创建一个使用此WebService的方法,但是我收到了一个错误。我可以使用其他webservice,但我没有创建它们(android上的方法)我很新,所以我想要一些帮助。

事件记录

W/System.err: SoapFault - faultcode: 'soap:Server' faultstring: 'Server was unable to process request. ---> Object reference not set to an instance of an object.' faultactor: 'null' detail: org.kxml2.kdom.Node@107d094
W/System.err:     at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:147)
W/System.err:     at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
W/System.err:     at org.ksoap2.transport.Transport.parseResponse(Transport.java:118)
W/System.err:     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:275)
W/System.err:     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
W/System.err:     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
W/System.err:     at org.tempuri.WsCambioCotacaoSoap.validateCoupon(WsCambioCotacaoSoap.java:1004)
W/System.err:     at com.rendimento.cotacao.home.onlineStore.payment.PurchaseDetailsActivity$1.run(PurchaseDetailsActivity.java:235)
W/System.err:     at java.lang.Thread.run(Thread.java:761)

//第1004行是: _ht.call(" http://tempuri.org/ValidateCoupon",_ envelope);

WebService请求

POST /wscambiocotacao/WsCambioCotacao.asmx HTTP/1.1
Host: hom.cotacao.com.br
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/ValidateCoupon"

<?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>
    <ValidateCoupon xmlns="http://tempuri.org/">
      <vOperID>long</vOperID>
      <vUserName>string</vUserName>
      <vToken>string</vToken>
      <vCouponID>string</vCouponID>
    </ValidateCoupon>
  </soap:Body>
</soap:Envelope>

WebService响应

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>
    <ValidateCouponResponse xmlns="http://tempuri.org/">
      <ValidateCouponResult>
        <Status>string</Status>
        <Code>string</Code>
        <Message>string</Message>
      </ValidateCouponResult>
    </ValidateCouponResponse>
  </soap:Body>
</soap:Envelope>

WebService类中的WebService方法(包含所有Web服务)

public org.tempuri.ValidateCoupon validateCoupon(long vOperID, java.lang.String vUserName, java.lang.String vToken, java.lang.String vCouponID) throws Exception {

    SoapObject _client = new SoapObject(NAMESPACE, "validateCoupon");
    _client.addProperty("vOperID", vOperID + "");
    _client.addProperty("vUserName", vUserName);
    _client.addProperty("vToken", vToken);
    _client.addProperty("vCouponID", vCouponID);

    SoapSerializationEnvelope _envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    _envelope.dotNet = true;
    _envelope.setOutputSoapObject(_client);
    WSHttpTransport _ht = new WSHttpTransport(Configuration.getWsUrl(), Configuration.getTimeout());
    _ht.debug = Util.Debug();
    _ht.call("http://tempuri.org/ValidateCoupon", _envelope);

    if(Util.Debug()) {

        Log.d(LOG_TAG, "ValidateCoupon request:"+_ht.requestDump);
        Log.d(LOG_TAG, "ValidateCoupon response:"+_ht.responseDump);

    }

    SoapObject _ret = (SoapObject) _envelope.getResponse();
    int _len = _ret.getPropertyCount();
    org.tempuri.ValidateCoupon _returned = new org.tempuri.ValidateCoupon();
    for(int _i = 0; _i < _len; _i++) {

        _returned.setProperty(_i, _ret.getProperty(_i));

    }

    return _returned;
}

tempuri包中的ValidacteCoupon的对象

public final class ValidateCoupon extends SoapObject {

    private java.lang.String status;
    private java.lang.String code;
    private java.lang.String message;

    public ValidateCoupon() {super("", ""); }

    public String getMessage() { return message; }

    public void setMessage(String message) { this.message = message; }

    public String getCode() { return code; }

    public void setCode(String code) { this.code = code; }

    public String getStatus() { return status; }

    public void setStatus(String status) { this.status = status; }

    public int getPropertyCount() { return 3; }


    public Object getProperty(int __index) {

        switch(__index) {

            case 0: return status;
            case 1: return code;
            case 2: return message;

        }

        return null;

    }

    public void setProperty(int __index, Object __obj) {

        switch(__index) {

            case 0: status = (java.lang.String) __obj.toString(); break;
            case 1: code = (java.lang.String) __obj.toString(); break;
            case 2: message = (java.lang.String) __obj.toString(); break;

        }


    }

    public void getPropertyInfo(int __index, Hashtable __table, PropertyInfo __info) {

        switch(__index) {

            case 0:
                __info.name = "status";
                __info.type = java.lang.String.class; break;
            case 1:
                __info.name = "code";
                __info.type = java.lang.String.class; break;
            case 2:
                __info.name = "message";
                __info.type = java.lang.String.class; break;
        }

    }

}

创建要在主类中使用的方法

private void validateCoupon() {

    showLoading();

    new Thread(new Runnable() {

        @Override
        public void run() {

            final Resources res = getResources();
            WsCambioCotacaoSoap ws = new WsCambioCotacaoSoap();

            try {

                HashMap<String, Object> session = session();
                long operationID = 0;
                if(session.containsKey("OpeID"))
                    operationID = (Long) session.get("OpeID");

                org.tempuri.ValidateCoupon data = ws.validateCoupon(operationID,
                        Util.getDataWithKey(PurchaseDetailsActivity.this, Util.USER_DEFAULT_LOGIN_BK),
                                Util.getDataWithKey(PurchaseDetailsActivity.this, Util.USER_DEFAULT_KEY_TOKEN),
                                editTextCupom.getText().toString());

                if(data.getStatus().compareTo("OK") == 0) // sucess
                {
                    // // TODO: 12/2/16

                    Toast.makeText(PurchaseDetailsActivity.this, "Test compared to OK sucess", Toast.LENGTH_LONG);

                } else {

                    Toast.makeText(PurchaseDetailsActivity.this, "Test compared to OK failed", Toast.LENGTH_LONG);

                    if(data.getCode().compareTo("INVALID_TOKEN") == 0 || data.getCode().compareTo("EXPIRED_TOKEN") == 0) {

                        Util.alert(PurchaseDetailsActivity.this, new AlertDialog.Builder(PurchaseDetailsActivity.this)
                        .setTitle(res.getString(R.string.ALERT_OK_BUTTON))
                        .setMessage(data.getMessage())
                         .setNeutralButton(res.getString(R.string.ALERT_OK_BUTTON), new DialogInterface.OnClickListener() {

                            @Override

                            public void onClick(DialogInterface dialog, int which) {
                                // TODO Auto-generated method stub
                                PurchaseDetailsActivity.this.onLogoutClick();
                            }

                        }));

                    }

                }

            } catch (Exception e) {
                e.printStackTrace();
            }


            hideLoading();

        }

    }).start();

}

这就是我得到的所有信息。对于很长的问题我感到非常抱歉,但是 我真的需要一些帮助。我是初学者我甚至不知道从哪里开始,我根据已经创建的另一个Web服务方法创建了该方法(我的主管告诉我这样做)我无法向他寻求帮助,因为他说他对android一无所知所以我不得不谷歌一些。有人可以帮帮我吗?

0 个答案:

没有答案