org.ksoap2.serialization.SoapSerializationEnvelope [英] org.ksoap2.serialization.SoapSerializationEnvelope
问题描述
任何一个可以帮助我走出来清除这个错误?
我已经做了所有的设置...选定的jar文件中的Java构建路径也..我的文件夹也是在库的名字而已...当我使用的登录按钮与我的Android应用程序连接我的web服务错误显示它永远......
我的应用程序中包含有过期的证书网页证书的问题..我增加了code绕过证书错误...
但是,这SoapSerialization错误,当我点击登录按钮总是发生。
和这里是我的code
包com.test.mqilynx;
进口javax.net.ssl.HttpsURLConnection中;
进口javax.net.ssl.SSLContext;
进口javax.net.ssl.TrustManager;
进口javax.net.ssl.X509TrustManager;
进口org.ksoap2.SoapEnvelope;
进口org.ksoap2.serialization.SoapObject;
进口org.ksoap2.serialization.SoapSerializationEnvelope;
进口org.ksoap2.transport.HttpTransportSE;
进口android.app.Activity;
进口android.os.Bundle;
进口android.os.StrictMode;
进口android.util.Log;
进口android.view.Gravity;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.Button;
进口android.widget.EditText;
进口android.widget.Toast;
公共类MainActivity延伸活动{
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
如果(android.os.Build.VERSION.SDK_INT> 9){
。StrictMode.ThreadPolicy政策=新StrictMode.ThreadPolicy.Builder()permitAll()建();
StrictMode.setThreadPolicy(政策);
}
按钮loginb =(按钮)findViewById(R.id.button1);
loginb.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
EditText上的uname =(EditText上)findViewById(R.id.editText1);
EditText上PWD =(EditText上)findViewById(R.id.editText2);
。字符串USTR = uname.getText()的toString();
。字符串PSTR = pwd.getText()的toString();
如果(ustr.isEmpty()&安培;&安培; pstr.isEmpty()){
举杯= Toast.makeText(MainActivity.this,请登录凭据,Toast.LENGTH_SHORT);
to.setGravity(Gravity.CENTER,0,0);
以显示();
}
其他
{如果(ustr.isEmpty()|| pstr.isEmpty())
{
如果(ustr.isEmpty()){
举杯= Toast.makeText(MainActivity.this,请输入用户名,Toast.LENGTH_SHORT);
to.setGravity(Gravity.CENTER,0,0);
以显示();}
其他{
举杯= Toast.makeText(MainActivity.this,请输入密码,Toast.LENGTH_SHORT);
to.setGravity(Gravity.CENTER,0,0);
以显示();
}
}
其他
{
// Toast.makeText(getBaseContext(),欢迎光临!+ USTR +密码:+ PSTR,Toast.LENGTH_SHORT).show();
字符串METHOD_NAME =登陆;
字符串NAMESPACE =https://www.qilynx.com/loadsoap.php;
字符串SOAP_ACTION =https://www.qilynx.com/loadsoap.php/Login;
//字符串的URL =https://开头身份验证:1qaz2wsx3edc4rfv@www.qilynx.com/loadsoap.php递减?;
字符串的URL =https://www.qilynx.com:443/loadsoap.php;
SoapObject userReq =新SoapObject(命名空间METHOD_NAME);
userReq.addProperty(用户,美国贸易代表办公室);
userReq.addProperty(通,PSTR);
的System.out.println(用户:++ USTR +:+密码:+ PSTR);
// SoapObject请求=新SoapObject(命名空间METHOD_NAME);
// request.addProperty(登录,userReq);
SoapSerializationEnvelope包=新SoapSerializationEnvelope(SoapEnvelope.VER11);
// envelope.bodyOut =请求;
envelope.dotNet = TRUE;
envelope.setOutputSoapObject(userReq);
Log.e(REQ价值,userReq.toString());
Log.e(包络值,envelope.toString());
// Log.i(bodyenv,envelope.bodyOut.toString());
HttpTransportSE androidHTTPTransport =新HttpTransportSE(URL);
//通过传递证书 - 启动
//创建一个信任管理器不验证证书链
的TrustManager [] trustAllCerts =新的TrustManager [] {
新X509TrustManager(){
公共java.security.cert.X509Certificate [] getAcceptedIssuers(){
返回null;
}
公共无效checkClientTrusted(
java.security.cert.X509Certificate []证书,字符串的authType){
}
公共无效checkServerTrusted(
java.security.cert.X509Certificate []证书,字符串的authType){
}
}
};
//安装所有信任信任管理器
尝试 {
的SSLContext SC = SSLContext.getInstance(SSL);
sc.init(NULL,trustAllCerts,新java.security.SecureRandom中的());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
}赶上(例外五){
e.printStackTrace();
}
//通过传递证书 - 完
尝试{
的System.out.println(我在试试);
的System.out.println(envelope1+包);
androidHTTPTransport.setXmlVersionTag(&所述;?xml的版本= \1.0 \编码= \UTF-8 \>?);
的System.out.println(以前BP1);
的System.out.println(BP 1);
androidHTTPTransport.call(SOAP_ACTION,包);
的System.out.println(之后BP1);
的System.out.println(BP 2);
SoapObject resultsRequestSOAP =(SoapObject)envelope.bodyIn;
Log.v(TAG,将String.valueOf(resultsRequestSOAP));
的System.out.println(envelope2+包);
的System.out.println(前RESP);
SoapObject RESP =(SoapObject)envelope.getResponse();
Log.i(回归,resp.toString());
布尔查= Boolean.parseBoolean(resp.getProperty(结果)的toString());
如果(检查)
{
的System.out.println(成功登录);
/ *举杯= Toast.makeText(MainActivity.this,登录,Toast.LENGTH_SHORT);
to.setGravity(Gravity.CENTER,0,0);
以显示(); * /
}
其他
{
/ *举杯= Toast.makeText(MainActivity.this,失败,Toast.LENGTH_SHORT);
to.setGravity(Gravity.CENTER,0,0);
以显示();*/
的System.out.println(登录失败);
}
}
赶上(例外五)
{
的System.out.println(我在ERROR);
e.printStackTrace();
}
}
}
}
});
}
}
在code,因为他们行androidHTTPTransport.call(SOAP_ACTION,包);来自该行的code不工作...
在logcat中显示类似下面的错误
6月12号至24号:17:13.968:信封的E /值(13752):org.ksoap2.serialization.SoapSerializationEnvelope@417c87b0
((按钮)findViewById(R.id.btnData))。setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
NAMESPACE =http://tempuri.org/;
URL =HTTP://YOURURL/Service.asmx;
SOAP_ACTION =http://tempuri.org/SetLoginData;
METHOD_NAME =SetLoginData;
EditText上的uname =(EditText上)findViewById(R.id.editText1);
EditText上PWD =(EditText上)findViewById(R.id.editText2);
字符串dataToSend =[{用户名:uname.getText()的toString(),密码:pwd.getText()的toString()}];
送出数据(dataToSend);
}
});
}
公共无效送出数据(字符串数据){
Log.d(TAG,送出数据);
Log.d(TAG,网址:+网址);
Log.d(TAG,行动:+ SOAP_ACTION);
。StrictMode.ThreadPolicy政策=新StrictMode.ThreadPolicy.Builder()permitAll()建();
StrictMode.setThreadPolicy(政策);
Log.d(TAG,创建);
SoapObject请求=新SoapObject(命名空间METHOD_NAME);
字符串dataToSend =数据;
Log.d(TAG,dataToSend:+ dataToSend);
的PropertyInfo FromCurrency =新的PropertyInfo();
FromCurrency.setName(strInputData);
FromCurrency.setValue(dataToSend);
FromCurrency.setType(为String.class);
request.addProperty(FromCurrency);
Log.d(TAG,信封);
//创建envelop.Envelop将被用来发送请求
SoapSerializationEnvelope包=新SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.implicitTypes = TRUE;
envelope.setAddAdornments(假);
envelope.setOutputSoapObject(要求);
//说,肥皂Web服务是一个.NET服务
envelope.dotNet = TRUE;
Log.d(TAG,URL);
HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);
尝试 {
Log.d(TAG,呼);
androidHttpTransport.call(SOAP_ACTION,包);
Log.d(TAG,CALL1);
SoapPrimitive响应=(SoapPrimitive)envelope.getResponse();
Log.d(TAG的回应:+ response.toString());
TextView的V =(TextView中)findViewById(R.id.currency);
v.setText(Retururn性反应的+=+ response.toString());
}赶上(例外五){
e.printStackTrace();
}
}
这个Web服务将JSON数据,这就是为什么我在JSON传递的数据。所以你要检查两个三件事情该命名空间是什么,XML或JSON数据,FromCurrency.setName(strInputData);这是#C开发商函数参数名称和互联网permision requried。
Can any one help me out to clear this error?
I have done all the settings... Selected the jar file in the java build path also.. my folder also in the name of libs only... when I connect my webservice with my android app using a login button the error shows it up always....
my app contains the certificate problem with a expired certificate webpage.. and I added the code to bypass the certificate error...
But this SoapSerialization error always occurs when I click the login button..
and here Is my code
package com.test.mqilynx;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
Button loginb = (Button) findViewById(R.id.button1);
loginb.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
EditText uname = (EditText) findViewById(R.id.editText1);
EditText pwd = (EditText) findViewById(R.id.editText2);
String ustr = uname.getText().toString();
String pstr = pwd.getText().toString();
if (ustr.isEmpty() && pstr.isEmpty()){
Toast to = Toast.makeText(MainActivity.this,"Please Login credentials",Toast.LENGTH_SHORT);
to.setGravity(Gravity.CENTER, 0, 0);
to.show();
}
else
{ if (ustr.isEmpty() || pstr.isEmpty())
{
if(ustr.isEmpty()){
Toast to = Toast.makeText(MainActivity.this,"Please Enter Username",Toast.LENGTH_SHORT);
to.setGravity(Gravity.CENTER, 0, 0);
to.show();}
else{
Toast to = Toast.makeText(MainActivity.this,"Please Enter Password",Toast.LENGTH_SHORT);
to.setGravity(Gravity.CENTER, 0, 0);
to.show();
}
}
else
{
// Toast.makeText(getBaseContext(),"Welcome! " + ustr + " Pwd: "+ pstr,Toast.LENGTH_SHORT).show();
String METHOD_NAME = "Login";
String NAMESPACE = "https://www.qilynx.com/loadsoap.php";
String SOAP_ACTION = "https://www.qilynx.com/loadsoap.php/Login";
// String URL = "https://auth:1qaz2wsx3edc4rfv@www.qilynx.com/loadsoap.php?desc";
String URL = "https://www.qilynx.com:443/loadsoap.php";
SoapObject userReq = new SoapObject(NAMESPACE,METHOD_NAME);
userReq.addProperty("user",ustr);
userReq.addProperty("pass",pstr);
System.out.println("user: " + "" + ustr + ":" + "Pwd: " + pstr);
// SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
// request.addProperty("Login", userReq);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
// envelope.bodyOut = request;
envelope.dotNet=true;
envelope.setOutputSoapObject(userReq);
Log.e("Value of Req", userReq.toString());
Log.e("Value of Envelope", envelope.toString());
// Log.i("bodyenv", envelope.bodyOut.toString());
HttpTransportSE androidHTTPTransport = new HttpTransportSE(URL);
//By-passing certificate - START
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
}
};
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
// By-passing certificate - END
try{
System.out.println("I AM IN TRY");
System.out.println("envelope1 "+envelope);
androidHTTPTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
System.out.println("Before Bp1");
System.out.println("Bp 1");
androidHTTPTransport.call(SOAP_ACTION,envelope);
System.out.println("after Bp1");
System.out.println("Bp 2");
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
Log.v("TAG",String.valueOf(resultsRequestSOAP));
System.out.println("envelope2 "+envelope);
System.out.println("before resp");
SoapObject resp = (SoapObject) envelope.getResponse();
Log.i("return", resp.toString());
boolean check = Boolean.parseBoolean(resp.getProperty("result").toString());
if(check)
{
System.out.println("SUCCESS LOGIN");
/*Toast to = Toast.makeText(MainActivity.this,"Logged In",Toast.LENGTH_SHORT);
to.setGravity(Gravity.CENTER, 0, 0);
to.show(); */
}
else
{
/*Toast to = Toast.makeText(MainActivity.this,"Failed",Toast.LENGTH_SHORT);
to.setGravity(Gravity.CENTER, 0, 0);
to.show();*/
System.out.println("LOGIN FAILED");
}
}
catch(Exception e)
{
System.out.println("I AM IN ERROR");
e.printStackTrace();
}
}
}
}
});
}
}
The code which have the line androidHTTPTransport.call(SOAP_ACTION,envelope); from this line the code is not working...
the logcat showing the error like below
12-24 06:17:13.968: E/Value of Envelope(13752): org.ksoap2.serialization.SoapSerializationEnvelope@417c87b0
((Button)findViewById(R.id.btnData)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
NAMESPACE = "http://tempuri.org/";
URL = "http://YOURURL/Service.asmx";
SOAP_ACTION = "http://tempuri.org/SetLoginData";
METHOD_NAME = "SetLoginData";
EditText uname = (EditText) findViewById(R.id.editText1);
EditText pwd = (EditText) findViewById(R.id.editText2);
String dataToSend="[{'UserID':uname.getText().toString() ,'Password':pwd.getText().toString() }]";
SendData(dataToSend);
}
});
}
public void SendData(String data){
Log.d(TAG, "SendData");
Log.d(TAG, "URL : "+URL);
Log.d(TAG, "ACTION: "+SOAP_ACTION);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Log.d(TAG, "Create");
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
String dataToSend=data;
Log.d(TAG, "dataToSend: "+dataToSend);
PropertyInfo FromCurrency = new PropertyInfo();
FromCurrency.setName("strInputData");
FromCurrency.setValue(dataToSend);
FromCurrency.setType(String.class);
request.addProperty(FromCurrency);
Log.d(TAG, "envelope");
// Create the envelop.Envelop will be used to send the request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.implicitTypes=true;
envelope.setAddAdornments(false);
envelope.setOutputSoapObject(request);
// Says that the soap webservice is a .Net service
envelope.dotNet = true;
Log.d(TAG, "URL");
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
Log.d(TAG, "call");
androidHttpTransport.call(SOAP_ACTION, envelope);
Log.d(TAG, "call1");
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
Log.d(TAG,"response:"+ response.toString());
TextView v = (TextView) findViewById(R.id.currency);
v.setText("Retururn Responce" + "= " + response.toString() );
} catch (Exception e){
e.printStackTrace();
}
}
This webservice will take json data that's why i had passed data in json. so you have to check two three things that namespace is what, xml or json data , FromCurrency.setName("strInputData"); which is #c developer function argument name and internet permision requried.
这篇关于org.ksoap2.serialization.SoapSerializationEnvelope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!