我正在尝试使用 ksoap2 向我的 .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。我可能没有正确使用 ksoap 库。我可以对我的代码做些什么来正确格式化信封?
第一屏.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) {
}
}