我想使用android使用soap web服务,但是我收到了这个错误
意外类型(位置:在java.io.InputStreamReader@b3d693b8中END_DOCUMENT null @ 1:1)
这是我的网络服务
<!--
Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10-b140319.1121 svn-revision#7b34660d6bc70e587e8ec81a17e4d76af68816a6.
-->
<!--
Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10-b140319.1121 svn-revision#7b34660d6bc70e587e8ec81a17e4d76af68816a6.
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://Services.model/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://Services.model/" name="SessionEJBEntityBeanService">
<types>
<xsd:schema>
<xsd:import namespace="http://Services.model/" schemaLocation="http://192.168.1.2:7101/Mobile_Survey-Model-webapp/SessionEJBEntityBeanService?xsd=1"/>
</xsd:schema>
</types>
<message name="getEntiteFindAll">
<part name="parameters" element="tns:getEntiteFindAll"/>
</message>
<message name="getEntiteFindAllResponse">
<part name="parameters" element="tns:getEntiteFindAllResponse"/>
</message>
<message name="queryByRange">
<part name="parameters" element="tns:queryByRange"/>
</message>
<message name="queryByRangeResponse">
<part name="parameters" element="tns:queryByRangeResponse"/>
</message>
<message name="mergeEntite">
<part name="parameters" element="tns:mergeEntite"/>
</message>
<message name="mergeEntiteResponse">
<part name="parameters" element="tns:mergeEntiteResponse"/>
</message>
<message name="persistEntite">
<part name="parameters" element="tns:persistEntite"/>
</message>
<message name="persistEntiteResponse">
<part name="parameters" element="tns:persistEntiteResponse"/>
</message>
<message name="removeEntite">
<part name="parameters" element="tns:removeEntite"/>
</message>
<portType name="SessionEJBEntityBeanService">
<operation name="getEntiteFindAll">
<input wsam:Action="findallaction" message="tns:getEntiteFindAll"/>
<output wsam:Action="http://Services.model/SessionEJBEntityBeanService/getEntiteFindAllResponse" message="tns:getEntiteFindAllResponse"/>
</operation>
<operation name="queryByRange">
<input wsam:Action="query" message="tns:queryByRange"/>
<output wsam:Action="http://Services.model/SessionEJBEntityBeanService/queryByRangeResponse" message="tns:queryByRangeResponse"/>
</operation>
<operation name="mergeEntite">
<input wsam:Action="http://Services.model/SessionEJBEntityBeanService/mergeEntiteRequest" message="tns:mergeEntite"/>
<output wsam:Action="http://Services.model/SessionEJBEntityBeanService/mergeEntiteResponse" message="tns:mergeEntiteResponse"/>
</operation>
<operation name="persistEntite">
<input wsam:Action="persistentite" message="tns:persistEntite"/>
<output wsam:Action="http://Services.model/SessionEJBEntityBeanService/persistEntiteResponse" message="tns:persistEntiteResponse"/>
</operation>
<operation name="removeEntite">
<input wsam:Action="http://Services.model/SessionEJBEntityBeanService/removeEntite" message="tns:removeEntite"/>
</operation>
</portType>
<binding name="SessionEJBEntityBeanServicePortBinding" type="tns:SessionEJBEntityBeanService">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="getEntiteFindAll">
<soap12:operation soapAction="findallaction"/>
<input>
<soap12:body use="literal"/>
</input>
<output>
<soap12:body use="literal"/>
</output>
</operation>
<operation name="queryByRange">
<soap12:operation soapAction="query"/>
<input>
<soap12:body use="literal"/>
</input>
<output>
<soap12:body use="literal"/>
</output>
</operation>
<operation name="mergeEntite">
<soap12:operation soapAction=""/>
<input>
<soap12:body use="literal"/>
</input>
<output>
<soap12:body use="literal"/>
</output>
</operation>
<operation name="persistEntite">
<soap12:operation soapAction="persistentite"/>
<input>
<soap12:body use="literal"/>
</input>
<output>
<soap12:body use="literal"/>
</output>
</operation>
<operation name="removeEntite">
<soap12:operation soapAction=""/>
<input>
<soap12:body use="literal"/>
</input>
</operation>
</binding>
<service name="SessionEJBEntityBeanService">
<port name="SessionEJBEntityBeanServicePort" binding="tns:SessionEJBEntityBeanServicePortBinding">
<soap12:address location="http://192.168.1.2:7101/Mobile_Survey-Model-webapp/SessionEJBEntityBeanService"/>
</port>
</service>
</definitions>
这是我在android中的课程
package in.ac.srmuniv.soapwebservice;
import java.util.ArrayList;
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.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.widget.TextView;
public class KsoapTestActivity extends Activity {
private final String NAMESPACE = "http://Services.model/";
//private final String URL = "http://10.0.2.2:7101/Mobile_Survey-Model-webapp/SessionEJBwebservicesBeanService?WSDL";
private final String URL = "http://192.168.1.2:7101/Mobile_Survey-Model-webapp/SessionEJBEntityBeanService?WSDL";
private final String SOAP_ACTION = "http://Services.model/findallaction";
private final String METHOD_NAME = "getEntiteFindAll ";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Log.e("eeeee", "e1");
if (android.os.Build.VERSION.SDK_INT > 9) {
Log.e("eeeee", "e2");
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
Log.e("eeeee", "e3");
StrictMode.setThreadPolicy(policy);
Log.e("eeeee", "e4");
}
Log.e("eeeee", "e5");
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
Log.e("eeeee", "e6");
PropertyInfo propInfo=new PropertyInfo();
Log.e("eeeee", "e7");
propInfo.type=PropertyInfo.INTEGER_CLASS;
Log.e("eeeee", "e8");
//adding parameters
//request.addProperty("a", 10);
//request.addProperty("b", 15);
Log.e("eeeee", "e9");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
Log.e("eeeee", "e10");
//envelope.dotNet = true;
Log.e("eeeee", "e11");
envelope.setOutputSoapObject(request);
Log.e("eeeee", "e12");
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
Log.e("eeeee", "e13");
try {
Log.e("eeeee", "e14");
androidHttpTransport.call(SOAP_ACTION, envelope);
Log.e("eeeee", "e15");
SoapObject response = (SoapObject)envelope.getResponse();
Log.e("Object response", response.toString());
TextView tv = new TextView(this);
Log.e("eeeee", "e16");
tv.setText("Output: "+response.toString());
Log.e("eeeee", "e17");
setContentView(tv);
Log.e("eeeee", "e18");
} catch (Exception e) {
Log.e("erreeeuuuurrrr", e.getMessage());
e.printStackTrace();
}
}
}
这就是日志给我看的
08-09 13:49:23.897: E/eeeee(1702): e1
08-09 13:49:23.897: E/eeeee(1702): e2
08-09 13:49:23.897: E/eeeee(1702): e3
08-09 13:49:23.907: E/eeeee(1702): e4
08-09 13:49:23.907: E/eeeee(1702): e5
08-09 13:49:23.907: E/eeeee(1702): e6
08-09 13:49:23.907: E/eeeee(1702): e7
08-09 13:49:23.907: E/eeeee(1702): e8
08-09 13:49:23.907: E/eeeee(1702): e9
08-09 13:49:23.907: E/eeeee(1702): e10
08-09 13:49:23.907: E/eeeee(1702): e11
08-09 13:49:23.907: E/eeeee(1702): e12
08-09 13:49:23.907: E/eeeee(1702): e13
08-09 13:49:23.907: E/eeeee(1702): e14
08-09 13:49:24.437: E/erreeeuuuurrrr(1702): unexpected type (position:END_DOCUMENT null@1:1 in java.io.InputStreamReader@b3d81d68)
08-09 13:49:24.437: W/System.err(1702): org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:1 in java.io.InputStreamReader@b3d81d68)
08-09 13:49:24.497: W/System.err(1702): at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java:2045)
08-09 13:49:24.497: W/System.err(1702): at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:126)
08-09 13:49:24.497: W/System.err(1702): at org.ksoap2.transport.Transport.parseResponse(Transport.java:90)
08-09 13:49:24.507: W/System.err(1702): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:179)
08-09 13:49:24.547: W/System.err(1702): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:90)
08-09 13:49:24.547: W/System.err(1702): at in.ac.srmuniv.soapwebservice.KsoapTestActivity.onCreate(KsoapTestActivity.java:58)
08-09 13:49:24.547: W/System.err(1702): at android.app.Activity.performCreate(Activity.java:5231)
08-09 13:49:24.547: W/System.err(1702): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-09 13:49:24.557: W/System.err(1702): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
08-09 13:49:24.557: W/System.err(1702): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
08-09 13:49:24.557: W/System.err(1702): at android.app.ActivityThread.access$800(ActivityThread.java:135)
08-09 13:49:24.557: W/System.err(1702): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
08-09 13:49:24.557: W/System.err(1702): at android.os.Handler.dispatchMessage(Handler.java:102)
08-09 13:49:24.567: W/System.err(1702): at android.os.Looper.loop(Looper.java:136)
08-09 13:49:24.567: W/System.err(1702): at android.app.ActivityThread.main(ActivityThread.java:5017)
08-09 13:49:24.567: W/System.err(1702): at java.lang.reflect.Method.invokeNative(Native Method)
08-09 13:49:24.567: W/System.err(1702): at java.lang.reflect.Method.invoke(Method.java:515)
08-09 13:49:24.567: W/System.err(1702): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-09 13:49:24.567: W/System.err(1702): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-09 13:49:24.567: W/System.err(1702): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
将ksoap jar升级到 3.3.0 并将soapEnvelop vesrion更改为 12