ksoap2-android如何查看正在发送的soap消息?

时间:2016-09-02 18:03:55

标签: android ksoap2

我已通过设置httpTransport.debug = true启用了调试模式。但是,httpTransport.requestDump没有显示任何内容。我可以提示为什么它不起作用吗?有什么办法可以查看信封中创建的肥皂信息吗?

非常感谢你的帮助。

final String NAMESPACE = getString(R.string.namespace);
final String METHOD_NAME = getString(R.string.method_name);
final String SOAP_ACTION = getString(R.string.soap_action);
final String SERVICE_URL = getString(R.string.service_url);
final String API_KEY = getString(R.string.api_key);

StringBuilder sb = new StringBuilder();
sb.append("<APIKey>");
sb.append(API_KEY);
sb.append("</APIKey><ISBN>");
sb.append(ean);
sb.append("</ISBN><Modifiers></Modifiers>");
Log.d(TAG, sb.toString());

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
// GetAvailabilityInfoRequest availability = new GetAvailabilityInfoRequest(API_KEY, ean);
request.addProperty("GetAvailabilityInfoRequest", sb.toString());

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

HttpTransportSE httpTransport = new HttpTransportSE(SERVICE_URL);
httpTransport.debug = true;
try {
    httpTransport.call(SOAP_ACTION, envelope);
    Log.d(TAG, httpTransport.requestDump);
    Log.d(TAG, httpTransport.responseDump);
} catch (Exception e) {
    Log.e(TAG, "Error ", e);
}

这是我的要求,

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
    xmlns:xsi="w3.org/2001/XMLSchema-instance";
    xmlns:xsd="w3.org/2001/XMLSchema";
    xmlns:soap="schemas.xmlsoap.org/soap/envelope/">; 
    <soap:Body>
        <GetAvailabilityInfoRequest xmlns="nlb.gov.sg/ws/CatalogueService">; 
            <APIKey>****APIKEY***</APIKey>
            <ISBN>9781579124854</ISBN>
            <Modifiers></Modifiers>
        </GetAvailabilityInfoRequest>
    </soap:Body>
</soap:Envelope>

最诚挚的问候, JN

1 个答案:

答案 0 :(得分:1)

我假设您正在尝试按如下方式创建请求,

<Body>
    <GetAvailabilityInfoRequest>
        <APIKey>key</APIKey>
        <ISBN>ean</ISBN>
        <Modifiers></Modifiers>
    </GetAvailabilityInfoRequest>
</Body>

此外,我认为您的METHOD_NAMEGetAvailabilityInfoRequest

尝试使用以下代码创建请求

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("APIKey", key);
request.addProperty("ISBN", ean);
request.addProperty("Modifiers", "");

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