[英]Call asmx Web service from android app using KSOAP
I am trying to send some data to a asmx soap web service, been trying but did managed to send. 我正在尝试将一些数据发送到asmx soap Web服务,虽然尝试过但确实发送成功。 the error I got is:
我得到的错误是:
08-13 20:51:12.571: W/System.err(8885): SoapFault - faultcode: 'soap:Server' faultstring: 'Server was unable to process request. 08-13 20:51:12.571:W / System.err(8885):SoapFault-错误代码:'soap:Server'错误字符串:'服务器无法处理请求。 ---> Value cannot be null.
--->值不能为null。 08-13 20:51:12.571: W/System.err(8885): SoapFault - faultcode: 'soap:Server' faultstring: 'Server was unable to process request.
08-13 20:51:12.571:W / System.err(8885):SoapFault-错误代码:'soap:Server'错误字符串:'服务器无法处理请求。 ---> Value cannot be null.
--->值不能为null。 08-13 20:51:12.571: W/System.err(8885): SoapFault - faultcode: 'soap:Server' faultstring: 'Server was unable to process request.
08-13 20:51:12.571:W / System.err(8885):SoapFault-错误代码:'soap:Server'错误字符串:'服务器无法处理请求。 ---> Value cannot be null.
--->值不能为null。
Here is the web servcie URL: http://87.248.129.182:8090/PostPhotoInfo.asmx 这里是网络servcie网址: http://87.248.129.182:8090/PostPhotoInfo.asmx
and the code: 和代码:
private final String NAMESPACE = "http://tempuri.org/";
private final String URL = "http://87.248.129.182:8090/PostPhotoInfo.asmx";
private final String SOAP_ACTION = "http://tempuri.org/PostPhotoInfo";
private final String METHOD_NAME = "PostPhotoInfo";
public void call_asmx() {
//Create request
// photoArray
SoapObject request = new SoapObject(URL, METHOD_NAME);
//SoapObject request2 = new SoapObject(NAMESPACE, "photoArray");
SoapObject IMG = new SoapObject(URL, "PhotoInfo");
PropertyInfo _date = new PropertyInfo();
_date.setName("Date");
_date.setValue("2016-08-12 15:45:00");
_date.setType(String.class);
PropertyInfo _Latitude = new PropertyInfo();
_Latitude.setName("Latitude");
_Latitude.setValue("12.5245123");
_Latitude.setType(double.class);
PropertyInfo _longtitude = new PropertyInfo();
_longtitude.setName("Longitude");
_longtitude.setValue("32.45345");
_longtitude.setType(double.class);
PropertyInfo _CardID = new PropertyInfo();
_CardID.setName("CardID");
_CardID.setValue(14);
_CardID.setType(int.class);
PropertyInfo _ParkingNo = new PropertyInfo();
_ParkingNo.setName("ParkingNo");
_ParkingNo.setValue(12);
_ParkingNo.setType(int.class);
PropertyInfo _Image = new PropertyInfo();
_Image.setName("Image");
_Image.setValue("<< IMAGE DATA >>>");
_Image.setType(Base64.class);
IMG.addProperty(_date);
IMG.addProperty(_Latitude);
IMG.addProperty(_longtitude);
IMG.addProperty(_CardID);
IMG.addProperty(_ParkingNo);
IMG.addProperty(_Image);
request.addSoapObject(IMG);
//Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
//Set output SOAP object
envelope.setOutputSoapObject(request);
//Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
//Invole web service
androidHttpTransport.call(SOAP_ACTION, envelope);
//Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
//Assign it to fahren static variable
fahren = response.toString();
} catch (Exception e) {
e.printStackTrace();
//Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
Any hint is much appreciated. 任何提示,不胜感激。
The code is not setting the NAMESPACE
and not adding the photoArray
该代码是不设置
NAMESPACE
,并且不添加photoArray
Try the following code: 尝试以下代码:
private void callWebservice() {
String NAMESPACE = "http://tempuri.org/";
String URL = "http://87.248.129.182:8090/PostPhotoInfo.asmx";
String SOAP_ACTION = "http://tempuri.org/PostPhotoInfo";
String METHOD_NAME = "PostPhotoInfo";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapObject photoArray = new SoapObject("", "photoArray");
SoapObject photoInfo = new SoapObject("", "PhotoInfo");
PropertyInfo date = new PropertyInfo();
date.setName("Date");
date.setValue("2016-08-12 15:45:00");
date.setType(String.class);
PropertyInfo latitude = new PropertyInfo();
latitude.setName("Latitude");
latitude.setValue("12.5245123");
latitude.setType(String.class);
PropertyInfo longtitude = new PropertyInfo();
longtitude.setName("Longitude");
longtitude.setValue("32.45345");
longtitude.setType(String.class);
PropertyInfo cardID = new PropertyInfo();
cardID.setName("CardID");
cardID.setValue("18");
cardID.setType(String.class);
PropertyInfo parkingNo = new PropertyInfo();
parkingNo.setName("ParkingNo");
parkingNo.setValue("20");
parkingNo.setType(String.class);
PropertyInfo image = new PropertyInfo();
image.setName("Image");
image.setValue("<Base64 String>");
image.setType(String.class);
photoInfo.addProperty(date);
photoInfo.addProperty(latitude);
photoInfo.addProperty(longtitude);
photoInfo.addProperty(cardID);
photoInfo.addProperty(parkingNo);
photoInfo.addProperty(image);
photoArray.addSoapObject(photoInfo);
request.addSoapObject(photoArray);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setAddAdornments(false);
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
String value = response.toString();
} catch (Exception e) {
e.printStackTrace();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.