Android HttpTransportSE请求转储提供NullPointerException
我正试图通过Android的Ksoap2访问Android中的Android HttpTransportSE请求转储提供NullPointerException,android,ksoap2,ksoap,httptransportse,Android,Ksoap2,Ksoap,Httptransportse,我正试图通过Android的Ksoap2访问Android中的webservice SoapObject创建完成后,bodyOut的S.O.p输出所需字符串。但是,当我对我创建的用于调用的HttpTransportSE对象执行requestDump时,会发生NullPointerException。换句话说,传输对象为null。这怎么会发生 Web服务位于 此服务与SoapUI配合使用效果非常好。 SoapUI请求: <soap:Envelope xmlns:soap="http://ww
webservice
SoapObject
创建完成后,bodyOut
的S.O.p输出所需字符串。但是,当我对我创建的用于调用的HttpTransportSE
对象执行requestDump
时,会发生NullPointerException
。换句话说,传输对象为null。这怎么会发生
Web服务位于
此服务与SoapUI配合使用效果非常好。
SoapUI请求:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:v1="http://schemas.icta.lk/xsd/crop/handler/v1/">
<soap:Header/>
<soap:Body>
<v1:getCropDataList>
<v1:code>ABK</v1:code>
</v1:getCropDataList>
</soap:Body>
</soap:Envelope>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<ns1:getCropDataListResponse xmlns:ns1="http://schemas.icta.lk/xsd/crop/handler/v1/">
<ns1:cropInfo>
<ns1:name>Ambul Kesel</ns1:name>
<ns1:price>35.0</ns1:price>
<ns1:location>Dambulla</ns1:location>
</ns1:cropInfo>
<ns1:cropInfo>
<ns1:name>Ambul Kesel</ns1:name>
<ns1:price>40.0</ns1:price>
<ns1:location>Dambulla</ns1:location>
</ns1:cropInfo>
</ns1:getCropDataListResponse>
</soapenv:Body>
</soapenv:Envelope>
public class CropInfo implements KvmSerializable {
private String name;
private float price;
private String location;
@Override
public Object getProperty(int arg0) {
switch (arg0){
case 0:
return name;
case 1:
return price;
case 2:
return location;
default:
return null;
}
}
@Override
public int getPropertyCount() {
return 3;
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
switch (arg0){
case 0:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Name";
break;
case 1:
arg2.type = Float.class;
arg2.name = "Price";
break;
case 2:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Location";
break;
default:
break;
}
}
@Override
public void setProperty(int arg0, Object arg1) {
switch(arg0){
case 0:
name = arg1.toString();
break;
case 1:
price = Float.parseFloat(arg1.toString());
case 2:
location = arg1.toString();
default:
break;
}
}
}
public void btnOnClick(View v){
String NAMESPACE = "http://schemas.icta.lk/xsd/crop/handler/v1/";
String URL = "http://220.247.225.202:9080/services/CropServiceProxy.CropServiceProxyHttpSoap12Endpoint";
String method_name = "getCropDataList";
String SOAP_ACTION = "http://schemas.icta.lk/xsd/crop/handler/v1/getCropDataList";
SoapObject soap_request = new SoapObject(NAMESPACE, method_name);
soap_request.addProperty("code", "ABK" );
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.setOutputSoapObject(soap_request);
envelope.addMapping(NAMESPACE, "cropInfo", CropInfo.class);
//envelope.dotNet=true;
Marshal floatMarshal = new MarshalFloat();
floatMarshal.register(envelope);
System.out.println("body out : " + envelope.bodyOut.toString());
//AndroidHttpTransport http_transport = new AndroidHttpTransport(URL);
HttpTransportSE http_transport = new HttpTransportSE(URL);
try {
//NullPointerException HERE
System.out.println(http_transport.requestDump);
http_transport.call(SOAP_ACTION, envelope);
//because we should expect a vector, two kinds of prices are given
Vector<CropInfo> result_array = (Vector<CropInfo>)envelope.getResponse();
if(result_array != null){
for (CropInfo current_crop: result_array){
System.out.println(current_crop.getName());
System.out.println(Float.toString(current_crop.getPrice()));
}
}
} catch (Exception e) {
e.printStackTrace();
answer.setText("error caught");
//System.out.println(http_transport.responseDump);
}
// String result_string[] = (String[])result;
//answer.setText("returned");
}
Web服务调用:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:v1="http://schemas.icta.lk/xsd/crop/handler/v1/">
<soap:Header/>
<soap:Body>
<v1:getCropDataList>
<v1:code>ABK</v1:code>
</v1:getCropDataList>
</soap:Body>
</soap:Envelope>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<ns1:getCropDataListResponse xmlns:ns1="http://schemas.icta.lk/xsd/crop/handler/v1/">
<ns1:cropInfo>
<ns1:name>Ambul Kesel</ns1:name>
<ns1:price>35.0</ns1:price>
<ns1:location>Dambulla</ns1:location>
</ns1:cropInfo>
<ns1:cropInfo>
<ns1:name>Ambul Kesel</ns1:name>
<ns1:price>40.0</ns1:price>
<ns1:location>Dambulla</ns1:location>
</ns1:cropInfo>
</ns1:getCropDataListResponse>
</soapenv:Body>
</soapenv:Envelope>
public class CropInfo implements KvmSerializable {
private String name;
private float price;
private String location;
@Override
public Object getProperty(int arg0) {
switch (arg0){
case 0:
return name;
case 1:
return price;
case 2:
return location;
default:
return null;
}
}
@Override
public int getPropertyCount() {
return 3;
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
switch (arg0){
case 0:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Name";
break;
case 1:
arg2.type = Float.class;
arg2.name = "Price";
break;
case 2:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Location";
break;
default:
break;
}
}
@Override
public void setProperty(int arg0, Object arg1) {
switch(arg0){
case 0:
name = arg1.toString();
break;
case 1:
price = Float.parseFloat(arg1.toString());
case 2:
location = arg1.toString();
default:
break;
}
}
}
public void btnOnClick(View v){
String NAMESPACE = "http://schemas.icta.lk/xsd/crop/handler/v1/";
String URL = "http://220.247.225.202:9080/services/CropServiceProxy.CropServiceProxyHttpSoap12Endpoint";
String method_name = "getCropDataList";
String SOAP_ACTION = "http://schemas.icta.lk/xsd/crop/handler/v1/getCropDataList";
SoapObject soap_request = new SoapObject(NAMESPACE, method_name);
soap_request.addProperty("code", "ABK" );
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.setOutputSoapObject(soap_request);
envelope.addMapping(NAMESPACE, "cropInfo", CropInfo.class);
//envelope.dotNet=true;
Marshal floatMarshal = new MarshalFloat();
floatMarshal.register(envelope);
System.out.println("body out : " + envelope.bodyOut.toString());
//AndroidHttpTransport http_transport = new AndroidHttpTransport(URL);
HttpTransportSE http_transport = new HttpTransportSE(URL);
try {
//NullPointerException HERE
System.out.println(http_transport.requestDump);
http_transport.call(SOAP_ACTION, envelope);
//because we should expect a vector, two kinds of prices are given
Vector<CropInfo> result_array = (Vector<CropInfo>)envelope.getResponse();
if(result_array != null){
for (CropInfo current_crop: result_array){
System.out.println(current_crop.getName());
System.out.println(Float.toString(current_crop.getPrice()));
}
}
} catch (Exception e) {
e.printStackTrace();
answer.setText("error caught");
//System.out.println(http_transport.responseDump);
}
// String result_string[] = (String[])result;
//answer.setText("returned");
}
public void btnOnClick(视图v){
字符串命名空间=”http://schemas.icta.lk/xsd/crop/handler/v1/";
字符串URL=”http://220.247.225.202:9080/services/CropServiceProxy.CropServiceProxyHttpSoap12Endpoint";
字符串方法\u name=“getCropDataList”;
字符串SOAP_ACTION=”http://schemas.icta.lk/xsd/crop/handler/v1/getCropDataList";
SoapObject soap\u request=新的SoapObject(名称空间、方法名称);
soap_request.addProperty(“代码”、“ABK”);
SoapSerializationEnvelope=新的SoapSerializationEnvelope(SoapEnvelope.VER12);
setOutputSoapObject(soap\U请求);
addMapping(名称空间,“cropInfo”,cropInfo.class);
//envelope.dotNet=true;
Marshal float Marshal=新的marshall float();
收信人登记簿(信封);
System.out.println(“body out:+envelope.bodyOut.toString());
//AndroidHttpTransport http_transport=新的AndroidHttpTransport(URL);
HttpTransportSE http_transport=新的HttpTransportSE(URL);
试一试{
//此处为NullPointerException
System.out.println(http_transport.requestDump);
http_transport.call(SOAP_操作、信封);
//因为我们应该期望一个向量,所以给出了两种价格
向量结果_数组=(向量)envelope.getResponse();
if(结果数组!=null){
用于(CropInfo当前\u裁剪:结果\u数组){
System.out.println(当前_crop.getName());
System.out.println(Float.toString(current_crop.getPrice());
}
}
}捕获(例外e){
e、 printStackTrace();
response.setText(“错误捕获”);
//System.out.println(http_transport.responseDump);
}
//字符串结果\u字符串[]=(字符串[])结果;
//答案:setText(“返回”);
}
有人能解释一下吗?您需要将传输
实例的字段设置为真
,然后调用调用(字符串,SoapEnvelope)
方法,以便设置请求转储
字段:
HttpTransportSE http_transport = new HttpTransportSE(URL);
http_transport.debug = true;
try {
http_transport.call(SOAP_ACTION, envelope);
System.out.println(http_transport.requestDump);
//...
您需要将Transport
实例的字段设置为true
,然后调用call(String,SoapEnvelope)
方法,以便设置requestDump
字段:
HttpTransportSE http_transport = new HttpTransportSE(URL);
http_transport.debug = true;
try {
http_transport.call(SOAP_ACTION, envelope);
System.out.println(http_transport.requestDump);
//...
谢谢你,丹尼尔。我点错菜了。进行了您建议的更正,我现在在call方法中发现一个XMLPullParser错误。我正在努力解决这个问题。@Daniel dude我发自内心地爱你你从哪里得到这些小事情的信息??!我问了一个不同的问题,这个问题的答案让我想到了@chamila遇到的一个问题,甚至回答者都忘了提到关于设置
httpTransport.debug=true代码>。。。哇,我被困在那里两个小时了,我现在真的很高兴。请原谅我的长篇大论。再次感谢!!谢谢你,丹尼尔。我点错菜了。进行了您建议的更正,我现在在call方法中发现一个XMLPullParser错误。我正在努力解决这个问题。@Daniel dude我发自内心地爱你你从哪里得到这些小事情的信息??!我问了一个不同的问题,这个问题的答案让我想到了@chamila遇到的一个问题,甚至回答者都忘了提到关于设置httpTransport.debug=true代码>。。。哇,我被困在那里两个小时了,我现在真的很高兴。请原谅我的长篇大论。再次感谢!!