运行我的android项目时遇到以下错误,我通过KSOAP2调用web服务。
“预期:END_TAG {http://schemas.xmlsoap.org/soap/envelope/}正文(位置:END_TAGhttp://schemas.xmlsoap.org/soap/envelope/} s:fault> java.io.InputStreamReader中的@ 1:742 @ 44ea98d0"
继承我的java代码:
public class LoginWebService extends Activity{
private static final String NAMESPACE = "http://tempuri.org/" ;
private static final String URL = "http://192.168.1.103/InspectWcf/InspectServiceWcf.svc";
private static final String CheckUserAuthentication_SOAP_ACTION =
"http://tempuri.org/IInspectService/CheckUserAuthenticationResponse";
private static final String METHOD_NAME = "CheckUserAuthentication";
EditText useridText,passText;
TextView errorText;
Button loginButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
useridText = (EditText)findViewById(R.id.userEditText);
passText = (EditText)findViewById(R.id.passEditText);
errorText = (TextView)findViewById(R.id.errorTextView);
loginButton = (Button)findViewById(R.id.loginButton);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
CheckAuthentication();
}
});
}
public void CheckAuthentication(){
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
// SoapObject parameter = new SoapObject(NAMESPACE, "CheckUserAuthentication");
request.addProperty("username", "survaa");
request.addProperty("password", "survaa");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
Log.d("envelope",envelope.toString());
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
Log.d("envelope", envelope.toString());
HttpTransportSE httpt = new HttpTransportSE(URL);
Log.d("httpt",httpt.toString());
try{
httpt.call(CheckUserAuthentication_SOAP_ACTION , envelope);
Log.d("httpt",httpt.toString());
SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
// String str = result.toString();
// Log.d("result", result.toString());
if(result != null){
errorText.setText("Correct UserId or Password");
}
else{
errorText.setText("Invalid UserId or Password");
}
}
catch(Exception e){
errorText.setText(e.getMessage());
}
}
}
答案 0 :(得分:1)
嗯,有两个选择:
a)错误与NAMESPACE,SOAP_ACTION,METHOD_NAME字符串有关。但如果你检查了它们,那么:
b)错误与您的网络服务有关。
根据我的经验(Ksoap2和Axis2),当客户端成功发送请求但尚未调用getResponse()方法时,会出现“expected:END_TAG”错误。
您是否有任何工具来检查SOAP消息的交换? 例如,您可以使用tcpdump来监视SOAP流量:
$sudo tcpdump -i eth0 -A -s 8080 -l 'dst host localhost and port 8080'
(eth0和端口8080可能与您不同)
如果您的Web服务返回原始对象(int,boolean等),您可以使用:
Object response = envelope.getResponse();
如果要返回一个复杂的对象(String等),那么:
SoapObject response = (SoapObject)envelope.getResponse();
(抱歉我的英文)。
答案 1 :(得分:0)
根据我的经验,当我们为SOAP_ACTION,METHOD_NAME,NAMESPACE或url等Web服务提供适当的条目时,会出现此错误。如果可能,请分享代码。
答案 2 :(得分:0)
我认为你的SOAP_ACTION是错的,它应该是
http://tempuri.org/CheckUserAuthentication
就是这样。这意味着NAMESPACE+"/"+METHODNAME
由于