SoapObject 结果返回 anyType{} 作为值 [英] SoapObject Result returns anyType{} as value

查看:39
本文介绍了SoapObject 结果返回 anyType{} 作为值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

package com.example.gramaniladharidetails;

import java.util.Vector;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.Marshal;
import org.ksoap2.serialization.MarshalFloat;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

  public class GramaNiladhari extends Activity {
private static String SOAP_ACTION1= "http://localhost/getGramaNiladhariData";
private static String NAMESPACE = "http://119.235.4.217/";
private static String METHOD_NAME1 = "getGramaNiladhariData";
private static String URL = "";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_grama_niladhari);


    b.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {


            final String gndLifeCode = prov;
            String LifeCode = "3-2-09-060";
            request.addProperty("gndLifeCode", LifeCode);
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);


            SupportThread st = new SupportThread();
            Log.i("Request", request.toString());
            st.execute(request);

        }
    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_grama_niladhari, menu);
    return true;
}

private class SupportThread extends
        AsyncTask<SoapObject, Object, SoapObject> {

    @Override
    protected SoapObject doInBackground(SoapObject... req) {
        SoapObject result = null;
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);

        envelope.setOutputSoapObject(req[0]);
        envelope.addMapping(NAMESPACE, "SerializeInfo",
                new SerializeInfo().getClass());

        Marshal floatMarshal = new MarshalFloat();
        floatMarshal.register(envelope);

        envelope.dotNet = true;

        try {
            envelope.encodingStyle = SoapSerializationEnvelope.XSD;
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            androidHttpTransport.debug = true;

            androidHttpTransport.call(SOAP_ACTION1, envelope);
            SoapObject result = (SoapObject) envelope.getResponse();



            if (envelope.bodyIn instanceof SoapFault) {
                String str = ((SoapFault) envelope.bodyIn).faultstring;
                Log.i("*******", str);

            } else {
                int elementCount = result.getPropertyCount();

                if (elementCount > 0) {
                    String element;

                    for (int i = 0; i < elementCount; i++) {


                        element = result.getProperty(i).toString();
                        Log.d("This is an element", Integer.toString(i)
                                + " --" + element);


                    }
                }

            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    @Override
    protected void onPostExecute(SoapObject result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);

        if (result != null) {
            String response_name = result.getName();

            TextView tv = (TextView) findViewById(R.id.textView5);
            tv.setText(result.getProperty(0).toString());
        }

        else {

            Toast.makeText(getApplicationContext(), "No Response",
                    Toast.LENGTH_LONG).show();

        } 
    }
}

}

我正在调用的网络服务方法返回一个名为 GramaNiladhari 的 complexType 对象.它由 5 种字符串类型组成.当我运行此代码时,我得到以下 SoapObject 结果.

The webservice method i am calling retuns a complexType Object called GramaNiladhari. It consists of 5 string types. When I run this code I get the following SoapObject result.

anyType{gnName=anyType{}; address=anyType{}; workingDays=anyType{}; gnDivision=anyType{}; contactNumber=anyType{}; } 

但在这里我缺少,它们被替换为 anyType{} .如何检索真实值?

But here i am missing the values,and they are replaced with anyType{} . How can I retrieve the real values ?

我已经编辑了我的问题.

这是解析后的 XML 请求.

This is the parsed request in XML.

    <v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:d="http://www.w3.org/2001/XMLSchema" 
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header /><v:Body>
<getGramaNiladhariData xmlns="http://119.235.4.217/GNService/">
<gndLifeCode i:type="d:string">1-1-21-065</gndLifeCode>
</getGramaNiladhariData></v:Body></v:Envelope>

这是调用网络服务后的结果.

And this is the result after calling the web service.

 <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <getGramaNiladhariDataResponse xmlns="http://localhost/"> <getGramaNiladhariDataResult><gnName /><address /><workingDays /><gnDivision /><contactNumber /></getGramaNiladhariDataResult></getGramaNiladhariDataResponse></soap:Body></soap:Envelope>

检查请求,似乎请求通过了(即使是请求参数 gndLifeCode 的正确值, 1-1-21-065 ).

Checking the request,it seems that the request has passed well(even the request parameter gndLifeCode with its correct value, 1-1-21-065 ).

但响应为空.我需要检索的所有元素都有空标签.

But the response, is null.All the elements I need to retrieve have empty tags.

这可能是网络服务中的问题吗?我已经在 SoapUI & 中检查了这个网络服务.它在那里工作得很好(即使它在 SoapClient 中也能工作).却无法弄清楚这里的问题是什么?

Can this be a problem in web service. I've checked this web service in SoapUI & it works well there(even it works in SoapClient). Yet can't figure out what the issue here is?

推荐答案

很抱歉,我不是 Android 开发人员,所以我无法为您提供确切的答案,但我可以给您一些提示我的观点出了什么问题

Sorry to say i am not a Android developer so i coudn't provide you the exact answer but i can give you some hints what going wrong with my view point

希望你的请求不太好理解我猜服务器

Hopefully your Request is not that much cool to understand i guess by the server

我认为你的要求是这样的

REQUEST:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/">
        <SOAP-ENV:Body>
            <ns1:getGramaNiladhariData/>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

所以它返回这个

stdClass Object
(
    [getGramaNiladhariDataResult] => stdClass Object
        (
            [gnName] => 
            [address] => 
            [workingDays] => 
            [gnDivision] => 
            [contactNumber] => 
        )

)

所以你的请求一定是这样的

REQUEST:
<?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/">
        <SOAP-ENV:Body>
            <ns1:getGramaNiladhariData>
                <ns1:gndLifeCode>3-2-09-060</ns1:gndLifeCode>
            </ns1:getGramaNiladhariData>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

然后你就会得到确切的答案

and then you will get the exact answer

还要确保您的 xmlns 标签(例如 ns1、SOAP-ENV(在我的情况下))相同,回顾一下我推荐使用soap ui

And also make sure your tags of xmlns such as ns1, SOAP-ENV (in my case) these are same, to review that i recommend to use soap ui

这篇关于SoapObject 结果返回 anyType{} 作为值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆