目标: 该应用调用Web服务,发送5个参数,用于标识远程数据库表中交换状态的选择条件。 webservice响应是文字正常,即正常执行。
问题: Webservice通常无错误运行(无异常),但检查远程数据库时未记录任何更新。就像Webservice运行未实现的提交一样。应用程序调试期间未显示错误。这一切都让我相信错误发生在我的应用程序中,因为当SoapUI 5.0.0软件运行相同的Web服务时,数据库会正确更新。我没有先进的知识来解决这个问题。谢谢你的帮助! 有关如何调试此问题的任何提示都是受欢迎的。
可能原因: 显然正在正确传递参数(请参阅下面的xml请求,该请求与SoapUI发送的xml完美匹配)。有没有办法知道xml请求是如何进入webservice的?如何调试?
感谢教程:http://programmerguru.com/android-tutorial/android-webservice-example/
示例SOAP 1.1 webservice(提取的WSDL定义)
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.
POST /wsv_teste/wsv.asmx HTTP/1.1
Host: 10.154.1.15
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/set_Bloqueia"
<?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>
<set_Bloqueia xmlns="http://tempuri.org/">
<Num>int</Num>
<DataAtual>string</DataAtual>
<Rua>string</Rua>
<Atividade>string</Atividade>
<ARB>string</ARB>
</set_Bloqueia>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<set_BloqueiaResponse xmlns="http://tempuri.org/">
调试应用,第1步 - HttpTransportSE.request
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<set_Bloqueia xmlns="http://tempuri.org/">
<Num>99</Num>
<DataAtual>24-AUG-2011</DataAtual>
<Rua>USJ-111</Rua>
<Atividade>LU</Atividade>
<ARB>LIN_PROP</ARB>
</set_Bloqueia>
</v:Body>
</v:Envelope>
调试应用,第2步 - HttpTransportSE.response
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<set_BloqueiaResponse xmlns="http://tempuri.org/">
<set_BloqueiaResult>OK</set_BloqueiaResult>
</set_BloqueiaResponse>
</soap:Body>
</soap:Envelope>
SoapUI测试 - WS完美运行(请求)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:set_Bloqueia>
<tem:Num>99</tem:Num>
<!--Optional:-->
<tem:DataAtual>24-AUG-2011</tem:DataAtual>
<!--Optional:-->
<tem:Rua>USJ-111</tem:Rua>
<!--Optional:-->
<tem:Atividade>LU</tem:Atividade>
<!--Optional:-->
<tem:ARB>LIN_PROP</tem:ARB>
</tem:set_Bloqueia>
</soapenv:Body>
</soapenv:Envelope>
SoapUI测试 - 其中WS完美运行(响应)
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<set_BloqueiaResponse xmlns="http://tempuri.org/">
<set_BloqueiaResult>OK</set_BloqueiaResult>
</set_BloqueiaResponse>
</soap:Body>
</soap:Envelope>
应用程序源代码(仅限必备)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.opcoes_baixar);
AsyncCallWS task = new AsyncCallWS();
task.execute();
private class AsyncCallWS extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
Log.i(TAG, "doInBackground");
testeBloqRua();
return null;
}
@Override
protected void onPostExecute(Void result) {
Log.i(TAG, "onPostExecute");
tv.setText(resultado);
formandoLayouts();// }
@Override
protected void onPreExecute() {
Log.i(TAG, "onPreExecute");
tv.setText("**Carregando...");
}
@Override
protected void onProgressUpdate(Void... values) {
Log.i(TAG, "onProgressUpdate");
}
}
public void testeBloqRua() {
String HOST = "http://10.154.1.15";
String NAMESPACE = "http://10.154.1.15/wsv_teste/";
String URL = "http://10.154.1.15/wsv_teste/wsv.asmx";
String SOAP_ACTION = "http://tempuri.org/set_Bloqueia";
String METHOD_NAME = "set_Bloqueia";
String resultWS = null;
SoapObject requestBloquear = new SoapObject("http://tempuri.org/", METHOD_NAME);
//Campos necessarios para bloquear
PropertyInfo bloquearNumPI = new PropertyInfo();
PropertyInfo bloquearDataAtualPI = new PropertyInfo();
PropertyInfo bloquearRuaPI = new PropertyInfo();
PropertyInfo bloquearAtividadePI = new PropertyInfo();
PropertyInfo bloquearArbPI = new PropertyInfo();
//Num
bloquearNumPI.setType(Integer.class);
bloquearNumPI.setName("Num");
bloquearNumPI.setValue(99);
requestBloquear.addProperty(bloquearNumPI);
//DataAtual
bloquearDataAtualPI.setType(String.class);
bloquearDataAtualPI.setName("DataAtual");
bloquearDataAtualPI.setValue("24-AUG-2011");
requestBloquear.addProperty(bloquearDataAtualPI);
//Rua
bloquearRuaPI.setType(String.class);
bloquearRuaPI.setName("Rua");
bloquearRuaPI.setValue("USJ-111");
requestBloquear.addProperty(bloquearRuaPI);
//Atividade
bloquearAtividadePI.setType(String.class);
bloquearAtividadePI.setName("Atividade");
bloquearAtividadePI.setValue("LU");
requestBloquear.addProperty(bloquearAtividadePI);
//Arb
bloquearArbPI.setType(String.class);
bloquearArbPI.setName("ARB");
bloquearArbPI.setValue("LIN_PROP");
requestBloquear.addProperty(bloquearArbPI);
SoapSerializationEnvelope envelopeBloquear = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//
envelopeBloquear.dotNet=true;
envelopeBloquear.setAddAdornments(false);
envelopeBloquear.implicitTypes=true;
envelopeBloquear.setOutputSoapObject(requestBloquear);
HttpTransportSE androidHttpBloquear = new HttpTransportSE(URL);
try
{
androidHttpBloquear.debug = true;
androidHttpBloquear.call(SOAP_ACTION, envelopeBloquear);
SoapObject responseBloquear = (SoapObject) envelopeBloquear.bodyIn;
resultWS = androidHttpBloquear.responseDump;
Log.i("t", "doInBackground");
}
catch(Exception e ) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
您的网络服务变量应该是那样的
String HOST = "http://10.154.1.15";
String NAMESPACE = "http://10.154.1.15/wsv_teste/";
String URL = "http://10.154.1.15/wsv_teste/wsv.asmx";
String SOAP_ACTION = "http://10.154.1.15/wsv_teste/";
String METHOD_NAME = "set_Bloqueia";
并替换此
SoapObject requestBloquear = new SoapObject("http://tempuri.org/", METHOD_NAME);
与
SoapObject requestBloquear = new SoapObject(NAMESPACE, METHOD_NAME);
答案 1 :(得分:0)
(代表OP发布)。
我终于找到了问题。该错误是soap-request xml元素之一。 &#34; ABR&#34;是错的。正确的名称是&#34; ARB&#34;。角色出现逆转。我至少失去了两天找到它。我为这个天真的错误道歉。