在android studio中反序列化操作wcf的请求消息体时出错

问题描述 投票:2回答:1

下面是我的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

android wcf soap-client xml-deserialization android-ksoap2
1个回答
0
投票

我能够解决这个问题只需调整下面的行

String NAMESPACE = "http://tempuri.org/IService1/";

新的和正确的

String NAMESPACE = "http://tempuri.org/";
© www.soinside.com 2019 - 2024. All rights reserved.