在android studio中反序列化操作wcf的请求消息体时出错
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在android studio中反序列化操作wcf的请求消息体时出错相关的知识,希望对你有一定的参考价值。
下面是我的android代码,我试图使用一个SOAP Web服务,即.svc?WSDL但它给我下面的错误(错误是在此代码之后),即使它在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 - faultcode:'a:InternalServiceFault'faultstring:'对操作'getStringVal'反序列化请求消息体时出错。 OperationFormatter遇到无效的Message正文。期望找到名为'getStringVal'的节点类型'Element'和名称空间'http://tempuri.org/'。找到名为'getStringVal'的节点类型'Element'和命名空间'http://tempuri.org/IService1/''faultactor:'null'详细信息:org.kxml2.kdom.Node@424a7188
答案
我能够解决这个问题只需调整下面的行
旧
String NAMESPACE = "http://tempuri.org/IService1/";
新的和正确的
String NAMESPACE = "http://tempuri.org/";
以上是关于在android studio中反序列化操作wcf的请求消息体时出错的主要内容,如果未能解决你的问题,请参考以下文章
C# Restful WCF 服务。无法在帖子正文中反序列化 XML
在 Visual Studio 中反序列化 JSON 文件时出错
如何在 Weka-for-Android 中反序列化保存的模型