ksoap2信封的格式不正确

时间:2013-04-16 19:04:38

标签: android ksoap2 android-ksoap2

我试图使用kso​​ap2将肥皂信封发送到我的.net网络服务。不幸的是它正在创建的信封,网络服务不喜欢。我在soapUI中对此进行了测试,得到的只是[](JSON)。 Ksoap正在产生:

<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>
    <getTest xmlns="http://www.carefusion.com/" id="o0" c:root="1">
       <testint i:type="d:int">16875</testint>
    </getTest>
  </v:Body>
</v:Envelope>

在soapUI中测试,Web服务真的想看到:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:car="http://carefusion.com/">
<soapenv:Header/>
  <soapenv:Body>
    <car:getTest>
      <car:testint>16874</car:testint>
    </car:getTest>
  </soapenv:Body>
</soapenv:Envelope>

返回我的JSON。我可能没有正确使用kso​​ap库。我可以对我的代码做什么来正确格式化信封?

FirstScreen.java

    package carefusion.com.MyTest;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ListView;
import android.widget.TextView;

public class FirstScreen extends Activity {

    /**Called when the activity is first created */
    private static final String URL="http://10.220.13.202:8080/Respiratory/ResService.asmx";
    private static final String SOAP_ACTION ="http://carefusion.com/getTest";
    private static final String METHOD_NAME ="getTest";
    private static final String NAMESPACE="http://www.carefusion.com/";
    private static final String param="16875";

    TextView tv;
    ListView lv;
    ArrayList<AgentMetric> agentMetricList = new ArrayList<AgentMetric>();
    AgentMetric agentObj = new AgentMetric();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first_screen);
        tv=(TextView)findViewById(R.id.TextView01);

        lv=(ListView)findViewById(R.id.ListView01);


     try
     {
          String response=  new RetrieveJson().execute(URL, SOAP_ACTION, METHOD_NAME, NAMESPACE, param).get();
          tv.setText(response);

     }




     catch(Exception e)
     {
          tv.setText(e.toString()); 

     }


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.first_screen, menu);
        return true;
    }

}

RetrieveJson.java

     package carefusion.com.MyTest;
import org.ksoap2.SoapEnvelope;
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.util.Log;



public class RetrieveJson extends AsyncTask  <String, Void, String>
{



    @Override
    protected String doInBackground(String... URL) {
        String result="";
        SoapObject Request=new SoapObject (URL[3].toString(),URL[2].toString());

        PropertyInfo pi = new PropertyInfo();
        pi.setName("testint");
        pi.setValue(Integer.parseInt(URL[4].toString()));
        pi.setType(int.class);
        Request.addProperty(pi);

        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.dotNet=true;
        soapEnvelope.setOutputSoapObject(Request);


        HttpTransportSE aht =new HttpTransportSE(URL[0].toString());
        aht.debug=true;

        try
        {

        aht.call(URL[1].toString(), soapEnvelope);
        SoapObject response = (SoapObject)soapEnvelope.bodyIn;
          result = response.getProperty(0).toString(); 
        }
        catch(Exception e)
        {
            e.printStackTrace();

        }
        finally{
           Log.i(getClass().getSimpleName(),"requestDump : "+aht.requestDump);
           Log.i(getClass().getSimpleName(),"responseDump : "+aht.responseDump);
}


        return result;
    }

    @Override
    protected void onPostExecute(String result) {


    }

}

0 个答案:

没有答案