沉舟侧畔千帆进,病树前头万木春。这篇文章主要讲述在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/";
StringSOAP_URL = "http://qasim.com.sa:90/Service1.svc?wsdl";
SoapPrimitive resultString;
String TAG = "Response";
String tempValue="https://www.songbingjia.com/android/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
答案【在android studio中反序列化操作wcf的请求消息体时出错】我能够解决这个问题只需调整下面的行
旧
String NAMESPACE = "http://tempuri.org/IService1/";
新的和正确的
String NAMESPACE = "http://tempuri.org/";
推荐阅读
- 为什么@GetMapping方法在发送响应时返回请求参数()
- AutoMapper(4.2+)Profile是逻辑还是基础设施的一部分()
- 如何为Xamarin.Android AlarmManager设置准确的时间
- 如何在app小部件中使用ListView并在android中填充数据()
- listView根本没有出现。安卓
- ü“ü土耳其人物在Android上投射
- Android XML解析listview
- Android(以编程方式突出显示listview中的当前选定选项)
- ListView崩溃。不工作的应用程序Android Studio模拟器