【发布时间】:2013-12-13 22:30:42
【问题描述】:
我正在做一个通过使用 ksoap2 使用网络服务的移动应用程序。
到目前为止,我能够通过包含 String、double、int 等的 web 服务发送复杂的对象...
然后我能够通过网络发送一个字节数组。现在我的问题来了:
当我尝试创建一个对象以通过网络发送时,其中一个参数是字节数组,我从服务器得到一个故障字符串。
我正在访问的网络服务具有以下 wsdl 文件:
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://sensors.components" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ax21="http://sensors.components/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://sensors.components">
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://sensors.components/xsd">
<xs:complexType name="Pic">
<xs:sequence>
<xs:element minOccurs="0" name="accuracy" type="xs:double"/>
<xs:element minOccurs="0" name="imageInByte" nillable="true" type="xs:base64Binary"/>
<xs:element minOccurs="0" name="latitude" type="xs:double"/>
<xs:element minOccurs="0" name="longitude" type="xs:double"/>
<xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="time" type="xs:long"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema xmlns:ax22="http://sensors.components/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://sensors.components">
<xs:import namespace="http://sensors.components/xsd"/>
<xs:element name="pictureWebservice">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="args0" nillable="true" type="ax21:Pic"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="pictureWebserviceResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="pictureWebserviceRequest">
<wsdl:part name="parameters" element="ns:pictureWebservice"/>
</wsdl:message>
<wsdl:message name="pictureWebserviceResponse">
<wsdl:part name="parameters" element="ns:pictureWebserviceResponse"/>
</wsdl:message>
<wsdl:portType name="PictureWSPortType">
<wsdl:operation name="pictureWebservice">
<wsdl:input message="ns:pictureWebserviceRequest" wsaw:Action="urn:pictureWebservice"/>
<wsdl:output message="ns:pictureWebserviceResponse" wsaw:Action="urn:pictureWebserviceResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="PictureWSSoap11Binding" type="ns:PictureWSPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="pictureWebservice">
<soap:operation soapAction="urn:pictureWebservice" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="PictureWSSoap12Binding" type="ns:PictureWSPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="pictureWebservice">
<soap12:operation soapAction="urn:pictureWebservice" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="PictureWSHttpBinding" type="ns:PictureWSPortType">
<http:binding verb="POST"/>
<wsdl:operation name="pictureWebservice">
<http:operation location="pictureWebservice"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="PictureWS">
<wsdl:port name="PictureWSHttpSoap11Endpoint" binding="ns:PictureWSSoap11Binding">
<soap:address location="http://accessible-serv.lasige.di.fc.ul.pt:8181/axis2/services/PictureWS.PictureWSHttpSoap11Endpoint/"/>
</wsdl:port>
<wsdl:port name="PictureWSHttpSoap12Endpoint" binding="ns:PictureWSSoap12Binding">
<soap12:address location="http://accessible-serv.lasige.di.fc.ul.pt:8181/axis2/services/PictureWS.PictureWSHttpSoap12Endpoint/"/>
</wsdl:port>
<wsdl:port name="PictureWSHttpEndpoint" binding="ns:PictureWSHttpBinding">
<http:address location="http://accessible-serv.lasige.di.fc.ul.pt:8181/axis2/services/PictureWS.PictureWSHttpEndpoint/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
我要发送的对象如下:
public class Pic implements KvmSerializable{
private double latitude;
private double longitude;
private long time;
private double accuracy;
private String name;
private byte[] imageInByte;
public byte[] getImageInByte() {
return imageInByte;
}
public void setImageInByte(byte[] imageInByte) {
this.imageInByte = imageInByte;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public double getAccuracy() {
return accuracy;
}
public void setAccuracy(double accuracy) {
this.accuracy = accuracy;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
@Override
public Object getProperty(int arg0) {
switch(arg0){
case 0:
return latitude;
case 1:
return longitude;
case 2:
return time;
case 3:
return accuracy;
case 4:
return name;
case 5:
return imageInByte;
}
return null;
}
@Override
public int getPropertyCount() {
return 6;
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
switch(arg0){
case 0:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "latitude";
break;
case 1:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "longitude";
break;
case 2:
arg2.type = PropertyInfo.LONG_CLASS;
arg2.name = "time";
break;
case 3:
arg2.type = Double.class;
arg2.name = "accuracy";
break;
case 4:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "name";
break;
case 5:
arg2.type = MarshalBase64.BYTE_ARRAY_CLASS;
arg2.name = "imageInBytes";
default:
break;
}
}
@Override
public void setProperty(int arg0, Object arg1) {
// TODO Auto-generated method stub
switch(arg0){
case 0:
latitude = Double.parseDouble(arg1.toString());
break;
case 1:
longitude = Double.parseDouble(arg1.toString());
break;
case 2:
time = Long.parseLong(arg1.toString());
break;
case 3:
accuracy = Double.parseDouble(arg1.toString());
break;
case 4:
name = arg1.toString();
break;
case 5:
imageInByte = (byte[])arg1;
default:
break;
}
}
我用来访问网络服务的值如下:
命名空间 = "http://sensors.components" 网址 = "http://accessible-serv.lasige.di.fc.ul.pt:8181/axis2/services/PictureWS?wsdl" 肥皂动作 = "http://sensors.components/pictureWebservice" 方法名 = "pictureWebservice"
然后我用来将其发送到网络服务的代码如下:
String NAMESPACE = "http://sensors.components/xsd";
try {
SoapObject request = new SoapObject(connection.getNAMESPACE(), connection.getMETHOD_NAME());
PropertyInfo object = new PropertyInfo();
object.setName("picture");
object.setValue(picture);
object.setType(picture.getClass());
object.setNamespace(NAMESPACE);
request.addProperty(object);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
MarshalDouble md = new MarshalDouble();
md.register(envelope);
new MarshalBase64().register(envelope);
envelope.addMapping(NAMESPACE, "Pic", new Pic().getClass());
HttpTransportSE androidHttpTransport = new HttpTransportSE(
connection.getURL());
androidHttpTransport.call(connection.getSOAP_ACTION(), envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
System.out.println("response: " + response.toString());
} catch (Exception e) {
e.printStackTrace();
}
虽然我之前尝试并成功地通过双精度对象传递对象并注册它们并能够传递 byte[],但我无法传递其中包含 byte[] 作为参数的复杂类型。
接下来会出现logcat错误:
SoapFault - faultcode: 'soapenv:Server' faultstring: 'Exception occurred while trying to invoke service method pictureWebservice' faultactor: 'null' detail: org.kxml2.kdom.Node@4153d588
12-13 22:26:51.363: W/System.err(5393): at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:112)
12-13 22:26:51.363: W/System.err(5393): at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:137)
12-13 22:26:51.363: W/System.err(5393): at org.ksoap2.transport.Transport.parseResponse(Transport.java:63)
12-13 22:26:51.363: W/System.err(5393): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)
12-13 22:26:51.363: W/System.err(5393): at memory.aid.webservices.WSClient.WSClientPictureFile(WSClient.java:92)
12-13 22:26:51.363: W/System.err(5393): at memory.aid.memoryaid.MemoryAid$1.run(MemoryAid.java:185)
12-13 22:26:51.363: W/System.err(5393): at android.os.Handler.handleCallback(Handler.java:615)
12-13 22:26:51.367: W/System.err(5393): at android.os.Handler.dispatchMessage(Handler.java:92)
12-13 22:26:51.367: W/System.err(5393): at android.os.Looper.loop(Looper.java:137)
12-13 22:26:51.367: W/System.err(5393): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-13 22:26:51.367: W/System.err(5393): at java.lang.reflect.Method.invokeNative(Native Method)
12-13 22:26:51.367: W/System.err(5393): at java.lang.reflect.Method.invoke(Method.java:511)
12-13 22:26:51.375: W/System.err(5393): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-13 22:26:51.375: W/System.err(5393): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-13 22:26:51.375: W/System.err(5393): at dalvik.system.NativeStart.main(Native Method)
有人有任何想法、解决方案或建议吗?非常感谢你。
编辑:
据我所知,问题是我在服务器的 web 服务中以某种方式调用 Pic 类中的 imageInByte 参数为空。没有其他参数为空。名称、纬度、经度、准确度和时间都是有效参数,但 imageInByte 为空。为什么?请帮忙
【问题讨论】:
-
发生的情况是,在 Web 服务的服务器中,Pic imageInByte 的参数为空。没有其他参数为空,只有 imageInByte。为什么?谁能帮我?到目前为止没有任何回应。
标签: android web-services soap wsdl ksoap2