在android中调用soap webservices

时间:2016-10-22 07:15:41

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

我是肥皂网服务的新手,在一个android中调用,我叫Url,我也发送参数,

我收到错误,错误是:服务器无法处理请求。 --->对象引用未设置为对象的实例。' faultactor:' null' detail:org.kxml2.kdom.Node

肥皂描述链接如下: selticketprice

调用soap webservices的java代码是:

                   protected String doInBackground(String... params) {
    // TODO Auto-generated method stub
    final SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_memberRegistration);
        // SerializationUtils.serialize(bFile);
        request.addProperty("fareMediaType", "SJT");
        request.addProperty("fromValue", "1");
        request.addProperty("toValue", "3");
        request.addProperty("ticketDate", "2016-09-29");
        request.addProperty("lang", "en");
        final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.headerIn = new Element[1];
        envelope.headerIn[0] = buildAuthHeader();
        new MarshalBase64().register(envelope);

        envelope.setOutputSoapObject(request);

        envelope.dotNet = true;
        HttpTransportSE androidHttpTransport = new HttpTransportSE(signUpURL);
        try {
            androidHttpTransport.call(SOAP_ACTION_memberRegistration, envelope);
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            res = response.toString();

        } catch (Exception e) {
            Log.e("exception", e.getMessage(),e);
        }

    return res;
}

private Element buildAuthHeader() {
    Element h = new Element().createElement(NAMESPACE, "AuthHeader");
    Element username = new Element().createElement(NAMESPACE, "Username");
    username.addChild(Node.TEXT, "name");
    h.addChild(Node.ELEMENT, username);
    Element pass = new Element().createElement(NAMESPACE, "Password");
    pass.addChild(Node.TEXT, "*******");
    h.addChild(Node.ELEMENT, pass);

    return h;
}     

1 个答案:

答案 0 :(得分:0)

您是否考虑过在不使用Soap库的情况下发出soap请求? 这更准确,您可以跟踪异常发生的位置而不是libs。对于服务更改且您无法使用库的长期情况,它也是最佳选择。在这里Call a soap webservice in android

回答我的回答