问题
I am getting the following error while running my android project in which I m calling a webservice through KSOAP2.
"expected:END_TAG{http://schemas.xmlsoap.org/soap/envelope/}Body(position:END_TAGhttp://schemas.xmlsoap.org/soap/envelope/}s:fault>@1:742 in java.io.InputStreamReader@44ea98d0"
Heres my java code:
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());
}
}
}
回答1:
Well, two options:
a) The error is related to the NAMESPACE, SOAP_ACTION, METHOD_NAME strings. But if you have checked them, then:
b) The error is related to your web service.
For my experience (Ksoap2 and Axis2) the "expected:END_TAG" error comes when the client has succesfully sent the request but hasn't called the getResponse() method.
Do you have any tool to check the interchange of SOAP messages? You can use tcpdump, for example, to monitor the SOAP traffic:
$sudo tcpdump -i eth0 -A -s 8080 -l 'dst host localhost and port 8080'
(eth0 and port 8080 maybe different for you)
If your web service is returning a primitive object (int, boolean, etc) you can use:
Object response = envelope.getResponse();
If is returning a complex object (String, etc) then:
SoapObject response = (SoapObject)envelope.getResponse();
(Sorry for my English).
回答2:
From my experience , this error comes when we dnt give proper entries for web service like SOAP_ACTION,METHOD_NAME,NAMESPACE or url . Share the code if possible .
回答3:
I think your SOAP_ACTION is wrong , it should be
http://tempuri.org/CheckUserAuthentication
thats it. it means NAMESPACE+"/"+METHODNAME
Thanks
来源:https://stackoverflow.com/questions/8179246/error-while-calling-a-web-service-svc-in-android-through-ksoap2