开发者

Web service problem with Android Ksoap2

开发者 https://www.devze.com 2023-03-05 08:04 出处:网络
I am developing an application which use Ksaop2 and Android 2.3.3 but I get the below error, can anyone help on this? thanks in advance.

I am developing an application which use Ksaop2 and Android 2.3.3 but I get the below error, can anyone help on this? thanks in advance.

WARN/System.err(591): org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:0 in java.io.InputStreamReader@4052fba0)

Here is my code:

package test.zlu.opo;

import java.io.UnsupportedEncodingException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;


public class StockQuoteService extends Activity {

private static final String NAMESPACE = "http://www.restfulwebservices.net/ServiceContracts/2008/01";

private static String URL = "http://www.restfulwebservices.net/wcf/StockQuoteService.svc?wsdl";

private static final String METHOD_NAME = "GetStockQuote";

private static String SOAP_ACTION = "GetStockQuote";


private String stockQuote;

private Button okButton;
private EditText textInput;
private ImageView imageView1;
private TextView textStockQuote;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    okButton = (Button)  findViewById(R.id.stockQuery);
    textInput = (EditText) findViewById(R.id.textStockCode);
    imageView1 = (ImageView) findViewById(R.id.ImageView01);
    textStockQuote = (TextView) findViewById(R.id.StockQuote);

    okButton.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            showStockQuote();
        }
   });
}

private void showStockQuote() {
    String stockCode = textInput.getText().toString();
    if (stockCode.length() == 0) stockCode = "";
    getStockQuote(stockCode);

    textStockQuote.setText(getStockQuote());
    //imageView1.setImageResource(getIconToday(0));
}

public void getStockQuote(String stockCode) {
    try {
        SoapObject rpc = new SoapObject(NAMESPACE, METHOD_NAME);

        rpc.addProperty("parameters", stockCode);

        HttpTransportSE ht = new HttpTransportSE(URL);
        ht.debug = true;

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        envelope.bodyOut = rpc;
        //envelope.dotNet= true;
        envelope.setOutputSoapObject(rpc);

        ht.call(SOAP_ACTION, envelope);

        SoapObject result = (SoapObject) envelope.bodyIn;
        System.out.println(result.toString());


    } catch (Exception e) {
        e.printStackTrace();
    }
}



private void parseResult(SoapObject detail) throws UnsupportedEncodingException{
    stockQuote = detail.getProperty(0).toString();

}


private String getStockQuote() {
    return stockQuote;
}
/*
private int getIconToday(int index) {
     return 1;
}*/
}

And here is the WSDL:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="StockQuoteService"
targetNamespace="http://www.restfulwebservices.net/ServiceContracts/2008/01"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
xmlns:tns="http://www.restfulwebservices.net/ServiceContracts/2008/01"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:wsa10="http://www.w3.org/2005/08/addressing"
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex">
  <wsdl:types>
    <xsd:schema targetNamespace="http://www.restfulwebservices.net/ServiceContracts/2008/01/Imports">

      <xsd:import schemaLocation="http://www.restfulwebservices.net/wcf/StockQuoteService.svc?xsd=xsd0"
      namespace="http://www.restfulwebservices.net/ServiceContracts/2008/01" />
      <xsd:import schemaLocation="http://www.restfulwebservices.net/wcf/StockQuoteService.svc?xsd=xsd3"
      namespace="http://GOTLServices.FaultContracts/2008/01" />
      <xsd:import schemaLocation="http://www.restfulwebservices.net/wcf/StockQuoteService.svc?xsd=xsd1"
      namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
      <xsd:import schemaLocation="http://www.restfulwebservices.net/wcf/StockQuoteService.svc?xsd=xsd2"
      namespace="http://www.restfulwebservices.net/DataContracts/2008/01" />
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="IStockQuoteService_GetStockQuote_InputMessage">

    <wsdl:part name="parameters" element="tns:GetStockQuote" />
  </wsdl:message>
  <wsdl:message name="IStockQuoteService_GetStockQuote_OutputMessage">

    <wsdl:part name="parameters"
    element="tns:GetStockQuoteResponse" />
  </wsdl:message>
  <wsdl:message name="IStockQuoteService_GetStockQuote_DefaultFaultContractFault_FaultMessage">

    <wsdl:part name="detail" element="q1:DefaultFaultContract"
    xmlns:q1="http://GOTLServices.FaultContracts/2008/01" />
  </wsdl:message>
  <wsdl:message name="IStockQuoteService_GetWorldMajorIndices_InputMessage">

    <wsdl:part name="parameters"
    element="tns:GetWorldMajorIndices" />
  </wsdl:message>
  <wsdl:message name="IStockQuoteService_GetWorldMajorIndices_OutputMessage">

    <wsdl:part name="parameters"
    element="tns:GetWorldMajorIndicesResponse" />
  </wsdl:message>
  <wsdl:message name="IStockQuoteService_GetWorldMajorIndices_DefaultFaultContractFault_FaultMessage">

    <wsdl:part name="detail" element="q2:DefaultFaultContract"
    xmlns:q2="http://GOTLServices.FaultContracts/2008/01" />
  </wsdl:message>
  <wsdl:portType name="IStockQuoteService">
    <wsdl:operation name="GetStockQuote">
      <wsdl:input wsaw:Action="GetStockQuote"
      message="tns:IStockQuoteService_GetStockQuote_InputMessage" />
      <wsdl:output wsaw:Action="http://www.restfulwebservices.net/ServiceContracts/2008/01/IStockQuoteService/GetStockQuoteResponse"
      message="tns:IStockQuoteService_GetStockQuote_OutputMessage" />
      <wsdl:fault wsaw:Action="http://www.restfulwebservices.net/ServiceContracts/2008/01/IStockQuoteService/GetStockQuoteDefaultFaultContractFault"
      name="DefaultFaultContractFault"
      message="tns:IStockQuoteService_GetStockQuote_DefaultFaultContractFault_FaultMessage" />
    </wsdl:operation>
    <wsdl:operation name="GetWorldMajorIndices">
      <wsdl:input wsaw:Action="GetWorldMajorIndices"
      message="tns:IStockQuoteService_GetWorldMajorIndices_InputMessage" />
      <wsdl:output wsaw:Action="http://www.restfulwebservices.net/ServiceContracts/2008/01/IStockQuoteService/GetWorldMajorIndicesResponse"
      message="tns:IStockQuoteService_GetWorldMajorIndices_OutputMessage" />
      <wsdl:fault wsaw:Action="http://www.restfulwebservices.net/ServiceContracts/2008/01/IStockQuoteService/GetWorldMajorIndicesDefaultFaultContractFault"
      name="DefaultFaultContractFault"
      message="tns:IStockQuoteService_GetWorldMajorIndices_DefaultFaultContractFault_FaultMessage" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="BasicHttpBinding_IStockQuoteService"
  type="tns:IStockQuoteService">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="GetStockQuote">
      <soap:operation soapAction="GetStockQuote"
      style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
      <wsdl:fault name="DefaultFaultContractFault">
        <soap:fault name="DefaultFaultContractFault"
        use="literal" />
      </wsdl:fault>
    </wsdl:operation>
    <wsdl:operation name="GetWorldMajorIndices">
      <soap:operation soapAction="GetWorldMajorIndices"
      style="document" />
      <wsdl:input>
        <soap:body开发者_开发问答 use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
      <wsdl:fault name="DefaultFaultContractFault">
        <soap:fault name="DefaultFaultContractFault"
        use="literal" />
      </wsdl:fault>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="StockQuoteService">
    <wsdl:port name="BasicHttpBinding_IStockQuoteService"
    binding="tns:BasicHttpBinding_IStockQuoteService">
      <soap:address location="http://www.restfulwebservices.net/wcf/StockQuoteService.svc" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
0

精彩评论

暂无评论...
验证码 换一张
取 消