我已经使用jax-ws创建了简单的Web服务.我需要在android中使用该webservice.
当我使用该Web服务时,出现此错误
org.xmlpull.v1.XmlPullParserException:意外类型(位置:END_document null @ 1:1,在java.io.inputStreamReader@40d310f0中)
我的wsdl代码:
<deFinitions targetnamespace="http://sample.jaxws.ws.blog.accrd.com/" name="SimpleWebServiceService"><types><xsd:schema><xsd:import namespace="http://sample.jaxws.ws.blog.accrd.com/" schemaLocation="http://localhost:8080/SimpleWebService/SimpleWebService?xsd=1"/></xsd:schema></types><message name="sayHello"><part name="parameters" element="tns:sayHello"/></message><message name="sayHelloResponse"><part name="parameters" element="tns:sayHelloResponse"/></message><portType name="SimpleWebService"><operation name="sayHello"><input wsam:Action="http://sample.jaxws.ws.blog.accrd.com/SimpleWebService/sayHelloRequest" message="tns:sayHello"/><output wsam:Action="http://sample.jaxws.ws.blog.accrd.com/SimpleWebService/sayHelloResponse" message="tns:sayHelloResponse"/></operation></portType><binding name="SimpleWebServicePortBinding" type="tns:SimpleWebService"><soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /><operation name="sayHello"><soap12:operation soapAction=""/><input><soap12:body use="literal"/></input><output><soap12:body use="literal"/></output></operation></binding><service name="SimpleWebServiceService"><port name="SimpleWebServicePort" binding="tns:SimpleWebServicePortBinding"><soap12:address location="http://localhost:8080/SimpleWebService/SimpleWebService"/></port></service></deFinitions>
我的活动:
public class MainActivity extends Activity { public final static String URL ="http://localhost:8080/SimpleWebService/SimpleWebService?wsdl"; public static final String nameSPACE = "http://sample.jaxws.ws.blog.accrd.com/"; public static final String SOAP_ACTION = "http://sample.jaxws.ws.blog.accrd.com/sayHello"; private static final String METHOD = "sayHello";@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main); final TextVIEw tv = (TextVIEw) findVIEwByID(R.ID.txt1); button btn = (button) findVIEwByID(R.ID.button1); btn.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { SoapObject request = new SoapObject(nameSPACE, METHOD); Customer cu = new Customer(); cu.setFirstname("Firstname"); cu.setLastname("Lastname"); PropertyInfo propInfo = new PropertyInfo(); propInfo.name = "arg0"; propInfo.type = Customer.class; request.addProperty(propInfo, cu); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER12); envelope.setoutputSoapObject(request); httpTransportSE androIDhttpTransport = new httpTransportSE(URL); try { androIDhttpTransport.call(SOAP_ACTION, envelope); Log.d("Error", "Finished"); SoapObject response=(SoapObject)envelope.bodyIn; tv.setText(response.toString()); } catch (Exception e) { Log.d("Error", e.toString()); } } });}}
我的Customer.java
public class Customer implements KvmSerializable { private String firstname; private String lastname; public String getFirstname() { return firstname; } public voID setFirstname(String firstname) { this.firstname = firstname; } public String getLastname() { return lastname; } public voID setLastname(String lastname) { this.lastname = lastname; } @OverrIDe public Object getProperty(int arg0) { Object object = null; switch (arg0) { case 0: object = this.firstname; break; case 1: object = this.lastname; break; } return object; } @OverrIDe public int getPropertyCount() { // Todo auto-generated method stub return 2; } @OverrIDe public voID getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo propertyInfo) { switch (arg0) { case 0: propertyInfo.name = "firstname"; propertyInfo.type = PropertyInfo.STRING_CLASS; break; case 1: propertyInfo.name = "lastname"; propertyInfo.type = PropertyInfo.STRING_CLASS; break; } } @OverrIDe public voID setProperty(int arg0, Object object) { switch (arg0) { case 0: this.firstname = object.toString(); break; case 1: this.lastname = object.toString(); break; } }}
当我在jax-ws网络服务中使用@BindingType为soap1.1时,我得到正确的响应.但是当我在jax-ws Web服务中使用@BindingType为soap1.2时,出现此错误org.xmlpull.v1.XmlPullParserException:意外类型(位置:java.io.inputStreamReader@40d310f0中的END_document null @ 1:1).
如何解决这个问题?
解决方法:
与@jeevamuthu交谈之后,问题在于他不得不将ksoap库添加到其构建路径中,并对代码进行较小的调整.如果您遇到类似的问题,请联系@jeevamuthu以获取解决此问题的信息.
PropertyInfo propInfo = new PropertyInfo(); propInfo.name = "arg0"; propInfo.value=cu; propInfo.type = Customer.class; request.addProperty(propInfo);
总结 以上是内存溢出为你收集整理的android-如何解决org.xmlpull.v1.XmlPullParserException:意外类型(位置:java.io.InputStreamReader@40d310f0中的END_DO全部内容,希望文章能够帮你解决android-如何解决org.xmlpull.v1.XmlPullParserException:意外类型(位置:java.io.InputStreamReader@40d310f0中的END_DO所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)