1

我将 Android java 与 WCF 服务连接起来。现在我正在尝试从 WCF 服务获取数据到我的项目中。

我对来自 C# 的 DataTable 类型有疑问,我必须将其解析到名为 Groups 的类中

现在我有序列化错误:

java.lang.ClassCastException: org.ksoap2.serialization.SoapObject 不能转换为 org.ksoap2.serialization.SoapPrimitive

网络服务 (WCF)

var sp = new StoreProcEgzequtor("[dbo].GetAddonsTypes");
string a = sp.SqlCommand.Connection.Database;
DataTable dt = sp.ExecuteDataTable("Tabela");
return dt;

班级组

public class Groups {
    private long id;
    private long ID2;
    private int flgW;
    private int flgO;
    private String Name;

活动

public class AndroidWSClientActivity extends Activity {

    private static final String METHOD_NAME = "GetAddonsTypes";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://10.0.2.2:53432/Service1.svc?wsdl";
    final String SOAP_ACTION = "http://tempuri.org/IService1/GetAddonsTypes";

    TextView textView;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wsclient_page);

    textView = (TextView) findViewById(R.id.textView2);


    Thread networkThread = new Thread() {
        @Override
        public void run() {
          try {
             SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);         
             SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
             envelope.setOutputSoapObject(request);

             HttpTransportSE ht = new HttpTransportSE(URL);
             ht.call(SOAP_ACTION, envelope);
             final  SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
             final String str = response.toString();

             runOnUiThread (new Runnable(){ 
         public void run() {
             Log.e("OK",str.toString());
               }
           });
          }
         catch (Exception e) {
            Log.e("WS", e.toString());
         }
        }
      };
      networkThread.start();
      }
}
4

1 回答 1

1

您的错误与以下行有关。它在异常中很清楚。请检查一下

final  SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

envelope.getResponse()返回 theSoapObject并且您将其转换为SoapPrimitive.

于 2013-04-16T14:31:10.657 回答