制作肥皂要求的问题

时间:2016-11-13 14:56:32

标签: java android soap android-ksoap2

我尝试使用kso​​ap2库版本3.6.2向soap API发出请求。

问题是我收到错误消息:

  

" SoapFault - faultcode:' soap:Server' faultstring:'服务器无法处理请求。 --->对象引用未设置为对象的实例。' faultactor:' null'详情:org.kxml2.kdom.Node@338a49b"。

我的代码如下所示:

String NAMESPACE = "x";
String METHOD_NAME = "x";
String SOAP_ACTION = "x";
String URL = "x";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

request.addProperty("userName", "x");
request.addProperty("Password", "x");

//request.addProperty("token","token","?");

Log.i("SOAP: ", request.toString());

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = false;
envelope.setOutputSoapObject(request);


HttpsTransportSE aht = new HttpsTransportSE("x", 8900, "x", 50000);
aht.debug = true;

// make call
try {

    aht.call(SOAP_ACTION, envelope);
    SoapObject result = (SoapObject) envelope.getResponse();

    Log.i("RESP:", aht.responseDump.toString());
    Log.i("RESPONSE: ", result.toString());

} catch (IOException e) {
    e.printStackTrace();
} catch (XmlPullParserException e) {
    e.printStackTrace();
}

我认为问题可能是需要一个属性,即我在代码中注释掉的属性。

如何添加属性属性?像这样:<token Token="">,因为我认为这是我错过的回复。

我用postman测试过它,效果很好,但只有当我拥有这3个属性(userName,Password和token)时才会这样做。

1 个答案:

答案 0 :(得分:1)

您可以使用addAttribute方法向属性添加属性。

试试这段代码,

request.addProperty("userName", "x");
request.addProperty("Password", "x");

SoapObject token = new SoapObject(NAMESPACE, "token");
token.addAttribute("Token", "your_token");
request.addSoapObject(token);