我们在制定对仅使用 XML 协议的远程 API 的请求时遇到问题。我们使用 Apache CXF 项目将 WSDL 文件解析为可轻松导入到我们项目中的类型(.java 文件)。在 CXF 上使用默认参数 none。
我们不确定如何让 KSOAP2 根据接收到的类型来格式化 XML。任何帮助是极大的赞赏。
凯文
public class SOAPRequestTest {
private static final String NAMESPACE = "http://schemas.xmlsoap.org/soap/envelope/";
private static final String SERVER_HOST = "https://xx.xx.xx.xx/services/LoginService";
private static final String SERVER_METHOD = "urn:LoginService";
public void execute() {
Logger.d("--> Hello");
new Thread(new Runnable() {
@Override
public void run() {
SoapObject request = new SoapObject(NAMESPACE, SERVER_METHOD);
GetSecurityInfo getSecurityInfo = new GetSecurityInfo();
SecurityLogin securityLogin = new SecurityLogin();
securityLogin.setUserId("testUser");
securityLogin.setPassword("password");
securityLogin.setType("consumer");
securityLogin.setIP("128.2.20.181");
securityLogin.setLocale("en_US");
getSecurityInfo.setUser(securityLogin);
request.addAttribute("user", getSecurityInfo);
SoapSerializationEnvelope soapSerializationEnvelope = new SoapSerializationEnvelope(1);
soapSerializationEnvelope.addTemplate(request);
soapSerializationEnvelope.addMapping("http://xx.xxx.xxx.xxx", "user", GetSecurityInfo.class);
HttpTransportSE httpTransportSE = new HttpTransportSE(SERVER_HOST);
httpTransportSE.debug = true;
try {
httpTransportSE.call("getSecurityInfo", soapSerializationEnvelope);
Logger.d(httpTransportSE.requestDump);
SoapObject soapObject = (SoapObject) soapSerializationEnvelope.getResponse();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
}