在 android studio 中反序列化操作 wcf 的请求消息正文时出错
Error in deserializing body of request message for operation wcf in android studio
下面是我的 android 代码,我在其中尝试使用一个 .svc?WSDL 的 SOAP Web 服务
但是它给了我下面的错误(错误是在这段代码之后),即使我在 SoapUI 应用程序中测试时它工作正常。
任何人都可以帮我解决这个问题,谷歌搜索后我尝试了很多东西但没有运气..
package sa.com.abana.testws;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class MainActivity extends Activity {
String METHOD_NAME = "getStringVal";
String SOAP_ACTION = "http://tempuri.org/IService1/getStringVal";
String NAMESPACE = "http://tempuri.org/IService1/";
String SOAP_URL = "http://qasim.com.sa:90/Service1.svc?wsdl";
SoapPrimitive resultString;
String TAG = "Response";
String tempValue="Pakistan";
// SoapObject request;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CelsiusAsync celsiustofahr = new CelsiusAsync();
celsiustofahr.execute();
}
private class CelsiusAsync extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
try {
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("str1", tempValue);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
HttpTransportSE transport = new HttpTransportSE(SOAP_URL);
transport.call(SOAP_ACTION, soapEnvelope);
//Object obj = (Object)soapEnvelope.getResponse();
resultString = (SoapPrimitive) soapEnvelope.getResponse();
//SoapObject resp = (SoapObject)soapEnvelope.getResponse();
Log.i(TAG, "Result Celsius: " + resultString);
} catch (Exception ex) {
Log.e(TAG, "Error: " + ex.getMessage());
}
return null;
}
}
}
错误
SoapFault - 错误代码:'a:InternalServiceFault' 错误字符串:'反序列化操作 'getStringVal' 请求消息正文时出错。 OperationFormatter 遇到无效的消息正文。预期会找到名称为 'getStringVal' 且命名空间为“http://tempuri.org/'. Found node type 'Element' with name 'getStringVal' and namespace 'http://tempuri.org/IService1/”的节点类型 'Element' faultactor:'null' detail:org.kxml2.kdom.Node@424a7188
我能够解决这个问题只是调整下面的行
旧
String NAMESPACE = "http://tempuri.org/IService1/";
新的和正确的
String NAMESPACE = "http://tempuri.org/";
下面是我的 android 代码,我在其中尝试使用一个 .svc?WSDL 的 SOAP Web 服务 但是它给了我下面的错误(错误是在这段代码之后),即使我在 SoapUI 应用程序中测试时它工作正常。 任何人都可以帮我解决这个问题,谷歌搜索后我尝试了很多东西但没有运气..
package sa.com.abana.testws;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class MainActivity extends Activity {
String METHOD_NAME = "getStringVal";
String SOAP_ACTION = "http://tempuri.org/IService1/getStringVal";
String NAMESPACE = "http://tempuri.org/IService1/";
String SOAP_URL = "http://qasim.com.sa:90/Service1.svc?wsdl";
SoapPrimitive resultString;
String TAG = "Response";
String tempValue="Pakistan";
// SoapObject request;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CelsiusAsync celsiustofahr = new CelsiusAsync();
celsiustofahr.execute();
}
private class CelsiusAsync extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
try {
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("str1", tempValue);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
HttpTransportSE transport = new HttpTransportSE(SOAP_URL);
transport.call(SOAP_ACTION, soapEnvelope);
//Object obj = (Object)soapEnvelope.getResponse();
resultString = (SoapPrimitive) soapEnvelope.getResponse();
//SoapObject resp = (SoapObject)soapEnvelope.getResponse();
Log.i(TAG, "Result Celsius: " + resultString);
} catch (Exception ex) {
Log.e(TAG, "Error: " + ex.getMessage());
}
return null;
}
}
}
错误
SoapFault - 错误代码:'a:InternalServiceFault' 错误字符串:'反序列化操作 'getStringVal' 请求消息正文时出错。 OperationFormatter 遇到无效的消息正文。预期会找到名称为 'getStringVal' 且命名空间为“http://tempuri.org/'. Found node type 'Element' with name 'getStringVal' and namespace 'http://tempuri.org/IService1/”的节点类型 'Element' faultactor:'null' detail:org.kxml2.kdom.Node@424a7188
我能够解决这个问题只是调整下面的行
旧
String NAMESPACE = "http://tempuri.org/IService1/";
新的和正确的
String NAMESPACE = "http://tempuri.org/";