Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中从SOAP响应获取数据?_Android_Asp.net_Web Services_Soap - Fatal编程技术网

如何在android中从SOAP响应获取数据?

如何在android中从SOAP响应获取数据?,android,asp.net,web-services,soap,Android,Asp.net,Web Services,Soap,我试图做的是在ASP.NET中创建一个简单的Web服务,通过该Web服务从MSSQL服务器获取数据,并在我的android应用程序中使用该数据。作为一个新手,我尝试了以下链接。我使用了与本教程建议的相同的体系结构。但在分析结果中的结果Soap响应时出错。具体如下 <?xml version="1.0" encoding="utf-8"?> <soap:Envelope > xmlns:soap="http://schemas.xmlsoap.org/soap/envelo

我试图做的是在ASP.NET中创建一个简单的Web服务,通过该Web服务从MSSQL服务器获取数据,并在我的android应用程序中使用该数据。作为一个新手,我尝试了以下链接。我使用了与本教程建议的相同的体系结构。但在分析结果中的结果Soap响应时出错。具体如下

<?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><findContactResponse xmlns="http://tempuri.org/" />
> </soap:Body> </soap:Envelope>

谢谢你的帮助。

终于明白了

这是在增加财产。并稍微更改响应解析

这是为我编写的完整代码

希望它能帮助别人

private static final String SOAP_ACTION = "http://tempuri.org/findContact";

    private static final String OPERATION_NAME = "findContact";// your webservice web method name

    private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

    private static final String SOAP_ADDRESS = "http://10.0.2.2:58497/WebService/Service.asmx";

    protected static final String TAG = null;
    private static String fahren;

    TextView tvData1;
    EditText edata;
    Button button;
    String studentNo;
    String state;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvData1 = (TextView)findViewById(R.id.textView1);
        edata =(EditText)findViewById(R.id.editText1);

        button=(Button)findViewById(R.id.button1);

        button.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                studentNo=edata.getText().toString();
                new Submit().execute(studentNo);
            }
        });
    }

    private class Submit extends AsyncTask<String, Void, String> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

        }

        @Override
        protected String doInBackground(String... arg) {
            // TODO Auto-generated method stub
            SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
            PropertyInfo propertyInfo = new PropertyInfo();
            propertyInfo.type = PropertyInfo.STRING_CLASS;
            propertyInfo.name = "eid";
            propertyInfo.setValue(studentNo);
            request.addProperty(propertyInfo);//problem was here

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
            httpTransport.debug = true;
            try{ 
                httpTransport.call(SOAP_ACTION, envelope);

                Log.e("RequestDump", httpTransport.requestDump.toString());
                Log.e("ResponseDump", httpTransport.responseDump.toString());

                SoapObject result=(SoapObject)envelope.bodyIn;
                if(result!= null){
                    state = result.getProperty(0).toString();
                    Log.e("Found", state);
                }
                else{
                    Log.e("Obj", result.toString());
                }
            }  
            catch (Exception exception)   {
                Log.e("Exception", exception.toString());
            }
            return state;
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            tvData1.setText(result);
        }
    }
}

我还实现了一个异步任务,以消除主线程上的运行时异常。需要正确添加request.addPropertypropertyInfo。

他们要么疯了,要么找到了在AndroidIt上使用soap的简单方法,这对我帮助不大。我正在寻找在数据解析中出现arayindexoutofbound错误时该怎么办?或者我需要做什么才能从Soap Response@Anthony解析数据
String resultData=result.getProperty(0).toString();
private static final String SOAP_ACTION = "http://tempuri.org/findContact";

    private static final String OPERATION_NAME = "findContact";// your webservice web method name

    private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

    private static final String SOAP_ADDRESS = "http://10.0.2.2:58497/WebService/Service.asmx";

    protected static final String TAG = null;
    private static String fahren;

    TextView tvData1;
    EditText edata;
    Button button;
    String studentNo;
    String state;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvData1 = (TextView)findViewById(R.id.textView1);
        edata =(EditText)findViewById(R.id.editText1);

        button=(Button)findViewById(R.id.button1);

        button.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                studentNo=edata.getText().toString();
                new Submit().execute(studentNo);
            }
        });
    }

    private class Submit extends AsyncTask<String, Void, String> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

        }

        @Override
        protected String doInBackground(String... arg) {
            // TODO Auto-generated method stub
            SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
            PropertyInfo propertyInfo = new PropertyInfo();
            propertyInfo.type = PropertyInfo.STRING_CLASS;
            propertyInfo.name = "eid";
            propertyInfo.setValue(studentNo);
            request.addProperty(propertyInfo);//problem was here

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
            httpTransport.debug = true;
            try{ 
                httpTransport.call(SOAP_ACTION, envelope);

                Log.e("RequestDump", httpTransport.requestDump.toString());
                Log.e("ResponseDump", httpTransport.responseDump.toString());

                SoapObject result=(SoapObject)envelope.bodyIn;
                if(result!= null){
                    state = result.getProperty(0).toString();
                    Log.e("Found", state);
                }
                else{
                    Log.e("Obj", result.toString());
                }
            }  
            catch (Exception exception)   {
                Log.e("Exception", exception.toString());
            }
            return state;
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            tvData1.setText(result);
        }
    }
}