通过ArrayList的数据成Android的SOAP Web服务 [英] Pass ArrayList data into SOAP web service in android

查看:156
本文介绍了通过ArrayList的数据成Android的SOAP Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我需要数组列表数据传递到SOAP的Web服务。到目前为止,我有以下的code。

 公共类ResultActivity延伸活动{
    公共最后弦乐NAMESPACE =;
    公众最终字符串URL =;
    公共最后弦乐SOAP_ACTION_1 =;
    公共最后弦乐METHOD_NAME_1 =;

    ProgressDialog mProgressDialog;
    SoapObject mSoapObjectCompanyDetailResponse;

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        // TODO自动生成方法存根
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.result);

        的System.out.println(大小在resxusr+ OnLineApplication.mParserResults.size());
        的for(int i = 0; I< OnLineApplication.mParserResults.size();我++){

            的System.out.println(ID+ OnLineApplication.mParserResults.get(ⅰ).getCompanyId());
            的System.out.println(Q+ OnLineApplication.mParserResults.get(ⅰ).getQuestion());
            的System.out.println(A+ OnLineApplication.mParserResults.get(I).getAnswer());
        }

        新insertResult()执行()。
    }

    公共类insertResult扩展的AsyncTask<虚空,虚空,虚空> {

        @覆盖
        在preExecute保护无效(){
            // TODO自动生成方法存根
            super.on preExecute();
            mProgressDialog = ProgressDialog.show(ResultActivity.this,等待,取);
        }

        @覆盖
        保护无效doInBackground(虚空...... PARAMS){
            SoapObject请求=新SoapObject(命名空间METHOD_NAME_1);
            // request.addProperty(DT,);
            的for(int i = 0; I< OnLineApplication.mParserResults.size();我++){
                request.addProperty(CompanyID,30);
                request.addProperty(问题,OnLineApplication.mParserResults.get(我).getQuestion());
                request.addProperty(答案,OnLineApplication.mParserResults.get(我).getAnswer());
            }

            SoapSerializationEnvelope包=新SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = TRUE;
            envelope.setOutputSoapObject(要求);
            HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);

            尝试 {
                androidHttpTransport.call(SOAP_ACTION_1,包);
                mSoapObjectCompanyDetailResponse =(SoapObject)envelope.bodyIn;
                对象重新= NULL;
                重新= envelope.getResponse();

                Log.i(对myApp,mSoapObjectCompanyDetailResponse.toString());
                的System.out.println(重+ mSoapObjectCompanyDetailResponse.toString());
                // mStringCompanyID = re.toString();

            }赶上(例外五){
                e.printStackTrace();
            }
            返回null;
        }

        @覆盖
        保护无效onPostExecute(无效的结果){
            // TODO自动生成方法存根
            super.onPostExecute(结果);
            如果(mProgressDialog!= NULL){
                mProgressDialog.dismiss();
            }

        }

    }

}
 

我的XML WSDL服务是如下。

 < WSDL:类型>
    < S:元素的名称=insertResultUser>
    < S:复杂类型>
       &所述氏:序列GT;
        &所述氏:元件的minOccurs =0maxOccurs为=1名称=DT>
       < S:复杂类型>
         &所述氏:序列GT;
        < S:任何的minOccurs =0的maxOccurs =无界的命名空间=htt​​p://www.w3.org/2001/XMLSchema的processContents =宽松/>
           < S:任何的minOccurs =1命名空间=金塔:架构 - 微软COM:XML-的DiffGram-V1的processContents =宽松/>
                    &所述; /秒:序列GT;
                < / S:复杂类型>
               &所述; /秒:组件>
                &所述; /秒:序列GT;
             < / S:复杂类型>
               &所述; /秒:组件>
              < S:元素的名称=insertResultUserResponse>
             < S:复杂类型>
            &所述氏:序列GT;
             &所述氏:元件的minOccurs =0maxOccurs为=1名称=insertResultUserResult类型=S:串/>
            &所述; /秒:序列GT;
         < / S:复杂类型>
        &所述; /秒:组件>
     < / S:架构>
      < / WSDL:类型>
      < WSDL:端口类型>
     < WSDL:操作名称=insertResultUser>
     < WSDL:输入消息=TNS:insertResultUserSoapIn/>
       < WSDL:输出消息=TNS:insertResultUserSoapOut/>
        < / WSDL:操作>
        < / WSDL:端口类型>
 

下列数据结构是什么,我需要传递给上述的Web服务。

  DT = {anyType的DocumentElement = {anyType的问题= {anyType的CompanyID = 1;问= Android是什么?;答= OS; };

 题= anyType的{CompanyID = 1;问= Android是什么?;答= OS; };
 题= anyType的{CompanyID = 1;问= Android是什么?;答= OS; };
 题= anyType的{CompanyID = 1;问= Android是什么?;答= OS; };
  题= anyType的{CompanyID = 1;问= Android是什么?;答= OS; }; }; }; }; }
 

当我运行上面的code,我无法发布ArrayList的数据发送到服务器。在我的onCreate方法,我能打印我的ArrayList值。我该如何解决这个问题?

解决方案
  

试试这个code:

  SoapObject请求=新SoapObject(Wsdl_Target_NameSpace,
            METHOD_NAME);
    的for(int i = 0; I< Property_Key.size();我++){
        request.addProperty(Property_Key.get(i)中,Property_Value.get(ⅰ));
    }
    SoapSerializationEnvelope包=新SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.setOutputSoapObject(要求);
    HttpTransportSE androidHttpTransport = NULL;
    androidHttpTransport =新HttpTransportSE(Url_location);
    androidHttpTransport.call(Soap_Action,包);
    SoapObject结果=(SoapObject)envelope.bodyIn;
    矢量响应=(矢量)envelope.getResponse();
 

Hello, I need to pass Array-list data into soap web service. So far, I have the following code.

    public class ResultActivity extends Activity {
    public final String NAMESPACE = "";
    public final String URL = "";
    public final String SOAP_ACTION_1 = "";
    public final String METHOD_NAME_1 = "";

    ProgressDialog mProgressDialog;
    SoapObject mSoapObjectCompanyDetailResponse;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.result);

        System.out.println("Size In resxusr " + OnLineApplication.mParserResults.size());
        for (int i = 0; i < OnLineApplication.mParserResults.size(); i++) {

            System.out.println("ID " + OnLineApplication.mParserResults.get(i).getCompanyId());
            System.out.println("Q " + OnLineApplication.mParserResults.get(i).getQuestion());
            System.out.println("A " + OnLineApplication.mParserResults.get(i).getAnswer());
        }

        new insertResult().execute();
    }

    public class insertResult extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
            mProgressDialog = ProgressDialog.show(ResultActivity.this, "Wait", "Fetching");
        }

        @Override
        protected Void doInBackground(Void... params) {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_1);
            // request.addProperty("dt","");
            for (int i = 0; i < OnLineApplication.mParserResults.size(); i++) {
                request.addProperty("CompanyID", 30);
                request.addProperty("Question", OnLineApplication.mParserResults.get(i).getQuestion());
                request.addProperty("Answer", OnLineApplication.mParserResults.get(i).getAnswer());
            }

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            try {
                androidHttpTransport.call(SOAP_ACTION_1, envelope);
                mSoapObjectCompanyDetailResponse = (SoapObject) envelope.bodyIn;
                Object re = null;
                re = envelope.getResponse();

                Log.i("myApp", mSoapObjectCompanyDetailResponse.toString());
                System.out.println("re " + mSoapObjectCompanyDetailResponse.toString());
                // mStringCompanyID=re.toString();

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

        @Override
        protected void onPostExecute(Void result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            if (mProgressDialog != null) {
                mProgressDialog.dismiss();
            }

        }

    }

}

My XML WSDL service is as following.

    <wsdl:types>
    <s:element name="insertResultUser">
    <s:complexType>
       <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="dt">
       <s:complexType>
         <s:sequence>
        <s:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.w3.org/2001/XMLSchema" processContents="lax"/>
           <s:any minOccurs="1" namespace="urn:schemas-microsoft-com:xml-diffgram-v1" processContents="lax"/>
                    </s:sequence>
                </s:complexType>
               </s:element>
                </s:sequence>
             </s:complexType>
               </s:element>
              <s:element name="insertResultUserResponse">
             <s:complexType>
            <s:sequence>
             <s:element minOccurs="0" maxOccurs="1" name="insertResultUserResult" type="s:string"/>
            </s:sequence>
         </s:complexType>
        </s:element>
     </s:schema>
      </wsdl:types>
      <wsdl:portType>
     <wsdl:operation name="insertResultUser">
     <wsdl:input message="tns:insertResultUserSoapIn"/>
       <wsdl:output message="tns:insertResultUserSoapOut"/>
        </wsdl:operation>
        </wsdl:portType>

The following structure of data is what I need to pass to the web service as described above.

dt=anyType{DocumentElement=anyType{questions=anyType{CompanyID=1; Question=what is  android?; Answer=OS; };

 questions=anyType{CompanyID=1; Question=what is android?; Answer=OS; }; 
 questions=anyType{CompanyID=1; Question=what is android?; Answer=OS; };
 questions=anyType{CompanyID=1; Question=what is android?; Answer=OS; };
  questions=anyType{CompanyID=1; Question=what is android?; Answer=OS; }; }; }; }; }

When I run the above code I am unable to post the Arraylist data to the server. In my onCreate method, I am able to print my Arraylist values. How can I solve this?

解决方案

Try this code:

SoapObject request = new SoapObject(Wsdl_Target_NameSpace,
            Method_Name);
    for (int i = 0; i < Property_Key.size(); i++) {
        request.addProperty(Property_Key.get(i), Property_Value.get(i));
    }
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = null;
    androidHttpTransport = new HttpTransportSE(Url_location);
    androidHttpTransport.call(Soap_Action, envelope);
    SoapObject results = (SoapObject) envelope.bodyIn;
    Vector response = (Vector) envelope.getResponse();

这篇关于通过ArrayList的数据成Android的SOAP Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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