从android调用SOAP-JSON web服务时出现问题
您好,我正在使用Eclipse在android上开发,并尝试连接到.Net Web服务。webservice方法具有参数“usuario”和“password”,并返回布尔值 我使用ksoap2库来调用webservice,但是我遇到了问题,当我尝试调用webservice时,我的应用程序崩溃了 当我看到变量“transport”的响应头时,它会显示“HTTP/1.1500内部服务器错误”,所以我想可能是参数或其他方面有问题。我已经允许Android清单的internet连接权限 我正在模拟器上运行应用程序 这是我的密码:从android调用SOAP-JSON web服务时出现问题,android,json,web-services,ksoap2,Android,Json,Web Services,Ksoap2,您好,我正在使用Eclipse在android上开发,并尝试连接到.Net Web服务。webservice方法具有参数“usuario”和“password”,并返回布尔值 我使用ksoap2库来调用webservice,但是我遇到了问题,当我尝试调用webservice时,我的应用程序崩溃了 当我看到变量“transport”的响应头时,它会显示“HTTP/1.1500内部服务器错误”,所以我想可能是参数或其他方面有问题。我已经允许Android清单的internet连接权限 我正在模拟器上
public class EntrarActivity extends Activity {
///---Constantes para la invocación del servicio---
private static final String METHOD_NAME = "existeUsuario";
private static final String SOAP_ACTION = WebServiceConstants.NAMESPACE + EntrarActivity.METHOD_NAME;
///---Declaración de variables para consumir el servicio---
private SoapObject request;
private SoapSerializationEnvelope envelope;
private SoapPrimitive resultsRequestSoap;
///---Declaracion de variable para serializar/deserializar
Gson gson;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_entrar);
}
public void clicked_loginButton(View view)
{
String usuario = ((EditText)findViewById(R.id.editText_mail_entrar)).getText().toString();
String password = ((EditText)findViewById(R.id.editText_password_entrar)).getText().toString();
request = new SoapObject(WebServiceConstants.NAMESPACE, EntrarActivity.METHOD_NAME);
//---le agregamos los parametros---
request.addProperty("usuario", usuario);
request.addProperty("password", password);
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true; //por que es .NET
envelope.setOutputSoapObject(request);
HttpTransportSE transporte = new HttpTransportSE(WebServiceConstants.URL);
try {
transporte.call(EntrarActivity.SOAP_ACTION, envelope);
resultsRequestSoap = (SoapPrimitive)envelope.getResponse();
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
String strJson = resultsRequestSoap.toString();
}
}
尝试下载SoapUI并首先在SoapUI中生成请求。它允许您轻松地调整输入-这将帮助您将其缩小到SOAP请求代码中的问题或web服务的响应。一旦请求在SoapUI中工作,就可以将javasoap请求转储为字符串并比较两者。很可能,您正在构建的SOAP请求中忘记了一些东西。SoapUI将查询WSDL并通过添加服务构建一个示例请求:
http://<hostname>/webservice?WSDL
http:///webservice?WSDL
将模板生成的输出与发送到web服务的内容进行比较。尝试下载SoapUI并首先在SoapUI中生成请求。它允许您轻松地调整输入-这将帮助您将其缩小到SOAP请求代码中的问题或web服务的响应。一旦请求在SoapUI中工作,就可以将javasoap请求转储为字符串并比较两者。很可能,您正在构建的SOAP请求中忘记了一些东西。SoapUI将查询WSDL并通过添加服务构建一个示例请求:
http://<hostname>/webservice?WSDL
http:///webservice?WSDL
将模板生成的输出与发送到web服务的内容进行比较。谢谢@torgis!问题是你的行动是错误的。通过SoapUI,我看到了正确的答案。再次感谢!!谢谢@torgis!问题是你的行动是错误的。通过SoapUI,我看到了正确的答案。再次感谢!!