尝试通过SOAP发送xml以获取特定响应。我试图使用默认引脚登录。正确的响应将包括用户ID但正在变为零。
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
// Create the soap request object
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
// Set the property info for the to currency
PropertyInfo value = new PropertyInfo();
value.setName("xml");
value.setValue(xml);
value.setType(String.class);
request.addProperty(value);
// Create the envelop.Envelop will be used to send the request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.bodyIn;
result = response.getProperty(0).toString();
Log.i("RES", result);
} catch (Exception e) {
result = "EXCEP " + e.toString();
}
我的xml是
<?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>
<pinLogin xmlns="http://tempuri.org/">
<pin1>string</pin1>
<pin2>string</pin2>
<pin3>string</pin3>
<pin4>string</pin4>
</pinLogin>
我应该得到像这样的回复
<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>
<pinLoginResponse xmlns="http://tempuri.org/">
<pinLoginResult>
<username>string</username>
<userID>guid</userID>
<isBusinessUser>boolean</isBusinessUser>
<functionOk>boolean</functionOk>
<checkAmount>boolean</checkAmount>
<refundRequested>boolean</refundRequested>
<isPaid>boolean</isPaid>
<duplicateUser>boolean</duplicateUser>
<isvalid>boolean</isvalid>
<funsdok>boolean</funsdok>
<emailok>boolean</emailok>
<recorddbadded>boolean</recorddbadded>
<transisvalid>boolean</transisvalid>
<user2isvalid>boolean</user2isvalid>
</pinLoginResult>
</pinLoginResponse>
</soap:Body>
</soap:Envelope>
但是我得到了类似的东西
anyType{userID=00000000-0000-0000-0000-000000000000;isBusinessUser=false; functionOk=false; checkAmount=false;refundRequested=false; ispaid=false; duplicateUser=false;
isValid=false; funsdok=false;emailok=false;recorddbadded=false;
transisvalid=false;user2isvalid=false;}
有没有人知道什么是错的......
答案 0 :(得分:2)
终于成功破解了它。
对我来说最有用的是我最初在一个完整的字符串中提供数据并添加了一些来自edittext的数据现在我将引脚号分配给字符串并通过PropertyIndo将这些字符串添加到Soap请求中并添加了xmlversiontag。我添加了工作代码。
private final String NAMESPACE = "";
private final String URL = "";
private final String SOAP_ACTION = "";
private final String METHOD_NAME = "";
String _TAG = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
String pin1 = "a";
String pin2 = "b";
String pin3 = "8";
String pin4 = "d";
在我的soapCall方法
中StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo _pin1 = new PropertyInfo();
_pin1.setName("pin1");
_pin1.setValue(pin1);
_pin1.setType(String.class);
PropertyInfo _pin2 = new PropertyInfo();
_pin2.setName("pin2");
_pin2.setValue(pin2);
_pin2.setType(String.class);
PropertyInfo _pin3 = new PropertyInfo();
_pin3.setName("pin3");
_pin3.setValue(pin3);
_pin3.setType(String.class);
PropertyInfo _pin4 = new PropertyInfo();
_pin4.setName("pin4");
_pin4.setValue(pin4);
_pin4.setType(String.class);
request.addProperty(_pin1);
request.addProperty(_pin2);
request.addProperty(_pin3);
request.addProperty(_pin4);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.setXmlVersionTag(_TAG);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.bodyIn;
result = response.getProperty(0).toString();
Log.i("RES", result);
}
catch(Exception e){
Log.i("ERR" , e.toString());
}
还要在清单文件中添加Internet权限。我希望这对某人有用。