您好我正在尝试使用KSOAP2 2.6.2 android程序集连接到glassfish 3.1.1上部署的java WebService。来自我的android程序。 这是我的命名空间
public static final String SERVICE_NAMESPACE = "za.co.n7.mobilebackup";
public static final String SERVICE_URL = "http://ipaddress:8080/MobileBackupServiceImplService/MobileBackupServiceImpl/";
这是我的发送方式
final String METHOD_NAME = "Login";
SoapObject results = null;
SoapObject request = null;
HttpTransportSE loginHttpTransport = null;
try {
request = new SoapObject(MBUtil.SERVICE_NAMESPACE, METHOD_NAME);
request.addProperty("username", username);
request.addProperty("password", MBUtil.hashPassword(password));
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.bodyOut=request;
envelope.enc = SoapSerializationEnvelope.ENC;
envelope.env="http://schemas.xmlsoap.org/soap/envelope/";
// Web method call
loginHttpTransport = new HttpTransportSE(MBUtil.SERVICE_URL);
loginHttpTransport.debug = true;
loginHttpTransport.call(MBUtil.SERVICE_URL + METHOD_NAME, envelope);
results = (SoapObject) envelope.getResponse();
System.out.println("Received Result without issue");
} catch (Exception e) {
e.printStackTrace();
System.out.println(loginHttpTransport.requestDump);
System.out.println(loginHttpTransport.responseDump);
} finally {
finish();
}
我在DDMS LogCat中遇到以下错误。
04-08 15:30:42.508: W/System.err(1454): org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:0 in java.io.InputStreamReader@4056c7a8)
04-08 15:30:42.508: W/System.err(1454): at org.kxml2.io.KXmlParser.exception(KXmlParser.java:273)
04-08 15:30:42.508: W/System.err(1454): at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java:1413)
04-08 15:30:42.508: W/System.err(1454): at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:126)
04-08 15:30:42.508: W/System.err(1454): at org.ksoap2.transport.Transport.parseResponse(Transport.java:100)
04-08 15:30:42.519: W/System.err(1454): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:195)
04-08 15:30:42.519: W/System.err(1454): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
04-08 15:30:42.519: W/System.err(1454): at za.co.n7.mobilebackup.LoginActivity.connect(LoginActivity.java:149)
04-08 15:30:42.519: W/System.err(1454): at za.co.n7.mobilebackup.LoginActivity$DoLoginRequest.run(LoginActivity.java:116)
04-08 15:30:42.519: W/System.err(1454): at android.os.Handler.handleCallback(Handler.java:587)
04-08 15:30:42.519: W/System.err(1454): at android.os.Handler.dispatchMessage(Handler.java:92)
04-08 15:30:42.519: W/System.err(1454): at android.os.Looper.loop(Looper.java:123)
04-08 15:30:42.519: W/System.err(1454): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-08 15:30:42.519: W/System.err(1454): at java.lang.reflect.Method.invokeNative(Native Method)
04-08 15:30:42.519: W/System.err(1454): at java.lang.reflect.Method.invoke(Method.java:507)
04-08 15:30:42.519: W/System.err(1454): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-08 15:30:42.528: W/System.err(1454): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-08 15:30:42.528: W/System.err(1454): at dalvik.system.NativeStart.main(Native Method)
我已经复制了我的SOAP消息并将其粘贴到soapUI中并获得了结果。任何人都可以帮助我,我一直在努力奋斗几个小时。 以下是我的SOAP消息的示例
<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>
<n0:Login id="o0" c:root="1" xmlns:n0="za.co.n7.mobilebackup">
<username i:type="d:string">umohduke</username>
<password i:type="d:string">c4066ed69b81d6b2b25f76405195c83ddaeecd8dbd3866f17912b895a72bc059</password>
</n0:Login>
</v:Body>
</v:Envelope>
答案 0 :(得分:3)
试试这个方法:
使用Android将文件发送到网络服务器。
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(image);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
bitmap=BitmapFactory.decodeStream(fileInputStream);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] data = baos.toByteArray();
IMAGE= Base64.encodeBytes(data);
Log.e("THE IMAGE BYTES",""+IMAGE);
Image是要发送到Web服务器的字符串。
答案 1 :(得分:1)
我不确定但是试试这个:
public static final String SERVICE_NAMESPACE = "http://za.co.n7.mobilebackup";
而不是
public static final String SERVICE_NAMESPACE = "za.co.n7.mobilebackup";