0

我正在尝试将我的 Android 应用程序与我的 SOAP 网络服务接口,但我得到了意想不到的结果......

Soap 服务工作正常,它们已经用 SoapUI 进行了测试,WSDL 是有效的。我正在使用 ksoap2 lib 1.6.1 版

这是我的调用代码:

    try {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("prop1", 1);
        request.addProperty("prop2", "FR");
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);
        androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.debug = true;
        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapObject objetSOAP = (SoapObject)envelope.getResponse();
        Log.e("TESTSOAP", objetSOAP.getProperty(0).toString());
    }
    catch (Exception e){
        Log.i("androidHttpTransport.requestDump", androidHttpTransport.requestDump);
        e.printStackTrace();
        Log.i("androidHttpTransport.responseDump", androidHttpTransport.responseDump);


    }

我在“调用”方法中遇到了一个异常,即:

03-13 17:31:05.791: W/System.err(6020):     at 03-13 17:30:19.901: W/System.err(5976):            org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG .... @2:402 in java.io.InputStreamReader@46294968) 

奇怪的是,如果我使用 requestDump 在 SoapUI 中获取发送的信封进行尝试,它工作得非常好。我得到了预期的结果。但 responseDump 实际上是向我返回 wsdl 文件,而不是结果。就像 wsdl 是否被调用一样,但不是我试图调用的方法。

有人知道为什么吗?也许如何纠正它?

谢谢 !

4

2 回答 2

0

该死的,终于找到了解决方案(几个月后!)显然,

   androidHttpTransport = new HttpTransportSE(URL);

不应该指向 wsdl,而是指向 php 文件。

于 2012-10-05T15:47:20.700 回答
0

类 soapDemo 扩展 AsyncTask {

        private final ProgressDialog dialog = new ProgressDialog(MainActivity.this);
        private final String SOAP_ACTION = "YOUR_PATH";
        private final String METHOD_NAME = "METHOD_NAME";
        private final String NAMESPACE = "NAMESPACE (for ex.http://)";
        private final String URL = "URL";

    @Override
    protected void onPreExecute() 
    {
        this.dialog.setMessage("data Loading");
        this.dialog.show();
    }

    @Override
    protected Void doInBackground(Void... unused) 
    {

        SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
        Request.addProperty("KEY",  "VALUE");
        Request.addProperty("KEY",  "VALUE");

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

    try 
    {
        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapObject response = (SoapObject) envelope.getResponse();

        System.out.println("response"+response);
        int  Count = response.getPropertyCount();
        list= new String[Count];    


        for (int i = 0; i < Count; i++)
        {
           list[i] = response.getPropertyAsString(i).toString();
        }

    }

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

    @Override
    protected void onPostExecute(Void result)
    {

        if (this.dialog.isShowing()) 
        {
           this.dialog.dismiss();
        }
        if(exc)
        {
           Toast.makeText(MainActivity.this,"Error" , Toast.LENGTH_LONG).show();
        }
        else
        {
            spinner();
            exc=false;
        }
     }
    }

    public void spinner()
    {
        Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
        ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, list);
        adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner1.setAdapter(adapter1);

        spinner1.setOnItemSelectedListener(new OnItemSelectedListener() 
        {
            @Override
            public void onNothingSelected(AdapterView<?> parent)
            {

            }

            @Override
            public void onItemSelected(AdapterView<?> parent,View view, int pos, long id) 
            {
            // your code
            }

      });
    }
于 2015-10-12T05:33:46.940 回答