1

我在我的应用程序中使用 ksoap2.jar 进行 web 服务调用。在连接时,当我使用 Wi-fi 或模拟器进行测试时,服务器给出以下错误:org.xmlpull.v1.XmlPullParserException:意外类型(位置:END_DOCUMENT null@1:0 in java.io.InputStreamReader@6111a1f1 )

当我使用 SIM 卡进行测试时,它会抛出这个错误:java.io.InterruptedIOException: Local connection timed out after ~ 120000

我为此 Web 服务连接编写了以下代码:

    SoapObject rpc = new SoapObject(serviceNamespace, methodName);
        rpc.addProperty("UserID", "1");
        rpc.addProperty("UserName", "xyz");
        rpc.addProperty("ContactNo", "9014567890");
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        envelope.bodyOut = rpc;
        envelope.dotNet = true;
        envelope.encodingStyle = SoapSerializationEnvelope.ENC;

        HttpTransport ht = new HttpTransport(serviceUrl + getConnectionString().trim());
        ht.debug = true;
        System.out.println("debug true ------- ");
        ht.setXmlVersionTag(" version=\"1.0\" encoding=\"UTF-8\"?>");
        SoapObject  response = null;
        try
        {
            ht.call(soapAction, envelope);
             response = (SoapObject )envelope.getResponse();
             String resultbody = response.getProperty("updateUserDetailResult").toString();
        }
        catch(org.xmlpull.v1.XmlPullParserException ex2){

            resultLbl.setText(ex2.toString());
        }
        catch(Exception ex){
        String bah = ex.toString();
        resultLbl.setText(bah);
        }




/**
     * Looks through the phone's service book for a carrier provided BIBS network
     * 
     * @return The uid used to connect to that network.
     */
    private static String getCarrierBIBSUid() 
    {
        net.rim.device.api.servicebook.ServiceRecord[] records = ServiceBook.getSB().getRecords();
        int currentRecord;

        for (currentRecord = 0; currentRecord < records.length; currentRecord++) 
        {
            if (records[currentRecord].getCid().toLowerCase().equals("ippp")) {
                if (records[currentRecord].getName().toLowerCase().indexOf("bibs") >= 0) {
                    return records[currentRecord].getUid();
                }
            }
        }
        return null;
    }

    /**
     *  Getting the connection string based on the connection
     * @return
     */
    public static String getConnectionString() 
    {
        String connectionString = null;

        // Wifi is the preferred transmission method
        if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) 
        {
            connectionString = ";interface=wifi";

        }
        // Is the carrier network the only way to connect?
        else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) 
        {
            String carrierUid = getCarrierBIBSUid();
            if (carrierUid == null) 
            {
                // Has carrier coverage, but not BIBS. So use the carrier's TCP
                // network

                connectionString = ";deviceside=true";
            } 
            else 
            {
                // otherwise, use the Uid to construct a valid carrier BIBS
                // request

                connectionString = ";deviceside=false;connectionUID=" + carrierUid + ";ConnectionType=";
            }
        }

        // Check for an MDS connection instead (BlackBerry Enterprise Server)
        else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS)
        {
            connectionString = ";deviceside=false";

        }

        // If there is no connection available abort to avoid bugging the user
        // unnecssarily.
        else if (CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE) 
        {

        }

        // In theory, all bases are covered so this shouldn't be reachable.
        else 
        {
            connectionString = ";deviceside=true";
        }

        return connectionString;
    }

我正在使用预先验证的 ksoap jar 文件(ksoap2-j2me-core-prev-2.1.2.jar)。

我不知道哪里出了问题。我在论坛中搜索过,但没有得到正确的解决方案。

谢谢。

4

0 回答 0