android - 如何解决 org.xmlpull.v1.XmlPullParserException : unexpected type (position:END_DOCUMENT null@1:1 in java. io.InputStreamReader@40d310f0)

标签 android jax-ws ksoap2 android-ksoap2

我已经使用 jax-ws 创建了简单的网络服务。我需要在 android 中使用该 web 服务。 当我使用该网络服务时出现此错误 org.xmlpull.v1.XmlPullParserException:意外类型(位置:END_DOCUMENT null@1:1 in 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" style="document"/><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>

我的 Activity :

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";




@Override
protected 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());

            }

        }
    });

}}

我的客户.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 is soap1.1 时,我得到了正确的响应。但是当我在我的 jax-ws 网络服务中使用 @BindingType is soap1.2 时,我收到此错误).

如何解决这个问题?

最佳答案

在与@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 : unexpected type (position:END_DOCUMENT null@1:1 in java. io.InputStreamReader@40d310f0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17816871/

相关文章:

java - 新的邮件选择工具栏(如 Gmail)

android - 如何绘制用分隔线绘制的圆形边框描边?

java - Google Play 控制台堆栈跟踪

java - 如何检查房间数据库是否为空

java - 从 WSDL 文件生成 Java 代码

java - 在 Bluemix 服务器上发布端点

java - JAXB 在 writeTo 方法中写入 OutputStream

java - Android ksoap2 Web 服务获取 WSDL 的 XML 描述?

java - 如何在 Android 中通过 POST 请求查询 Web 服务?

java.lang.RuntimeException : Cannot serialize: float