在同一个活动中调用Web服务中的两个方法,给出异常

时间:2011-12-05 09:34:35

标签: android web-services

我在同一个活动中调用两个Web服务时遇到一个奇怪的问题。 虽然我一个接一个地调用两种Web服务方法给了我一个例外。 一切都是正确的,我不知道问题。 有人遇到过这个问题吗? 请求给我一些建议......

这是调用Web服务的代码:

   public static String getRelatedVideoResponse(String request, String url,
        String action, String method, String namespace, String value) {
    try {
         System.setProperty("http.keepAlive", "false");

        URL u = new URL(url);

        URLConnection uc = u.openConnection();
        HttpURLConnection connection = (HttpURLConnection) uc;

        connection.setRequestProperty("connection", "close");

        connection.setUseCaches(false);
        connection.setConnectTimeout(30000);
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestProperty("SOAPAction", action);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type",
                "text/xml;charset=UTF-8");

        OutputStream out = connection.getOutputStream();

        Writer wout = new OutputStreamWriter(out);

        wout.write(request);

        wout.flush();


        wout.close();
        Log.e("before buffer","buffer");

        BufferedReader rd = new BufferedReader(new InputStreamReader(
                connection.getInputStream()));
        Log.e("buffer",rd+"");
        Log.e("code...", connection.getResponseCode() + "");

        while ((StaticUtils.sRelResult = rd.readLine()) != null) {

            Log.e("result", StaticUtils.sRelResult);
            return StaticUtils.sRelResult;
        }

    } catch (MalformedURLException e) {

        e.printStackTrace();
    } catch (IOException e) {
        Log.e("error occured", "here");
        e.printStackTrace();
    }
    return StaticUtils.sRelResult;
}

的活动:

    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.searchvideos);
mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                // TODO Auto-generated method stub
                super.handleMessage(msg);
                switch (msg.what) {
                case SUCCESS:
                    s = "<tns:int xmlns:tns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">";
                    t = "</tns:int>";
                    buffer.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                    buffer.append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns=\"http://tempuri.org/\">");
                    buffer.append("<soap:Body><GetScoresForVideos><videoIDs>");
                    for (int i = 0; i < StaticUtils.sAlRelId.size(); i++) {
                        buffer.append(s + StaticUtils.sAlRelId.get(i) + t);
                    }
                    buffer.append("</videoIDs>");
                    buffer.append("</GetScoresForVideos></soap:Body></soap:Envelope>");
                    Log.e("bufer string", buffer.toString());
                    WsdlService s = new WsdlService();

                    s.getRelatedVideoResponse(buffer.toString(),
                            StaticUtils.URL, StaticUtils.RATE_ACTION,
                            StaticUtils.RATE_METHOD, StaticUtils.NAMESPACE, "");
break;
    }
        };

download();
}
private void download() {
        Runnable r = new Runnable() {

            public void run() {
                if (StaticUtils.checkNetworkStatus(getApplicationContext()) == true) {
                    WsdlService service = new WsdlService(
                            StaticUtils.NAMESPACE,
                            StaticUtils.RELATED_METHOD_NAME, StaticUtils.URL,
                            StaticUtils.RELATED_SOAP_ACTION);
                    String str = service.getResponseById(Integer
                            .valueOf(videoId));

                    Log.e("Related videos", str);
                    RelatedParser parser = new RelatedParser(str);
                    parser.parseRelatedVideos();
                    onSuccessDownload();
                } else {
                    onFailureDownload();
                }

            }
        };
        Thread t = new Thread(r);
        t.start();

    }
public void onSuccessDownload() {
        mHandler.sendEmptyMessage(SUCCESS);
    }

例外是:

12-05 14:55:11.604: WARN/System.err(3075): java.io.FileNotFoundException: http://192.80.62:48080/Services/v0.2.2/SampleService.svc?wsdl
12-05 14:55:11.613: WARN/System.err(3075):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:1162)
12-05 14:55:11.613: WARN/System.err(3075):     at com.utils.WsdlService.getRelatedVideoResponse(WsdlService.java:180)
12-05 14:55:11.613: WARN/System.err(3075):     at com.scopra.screens.RelatedVideos$2.handleMessage(RelatedVideos.java:146)
12-05 14:55:11.613: WARN/System.err(3075):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 14:55:11.613: WARN/System.err(3075):     at android.os.Looper.loop(Looper.java:123)
12-05 14:55:11.613: WARN/System.err(3075):     at android.app.ActivityThread.main(ActivityThread.java:4627)
12-05 14:55:11.613: WARN/System.err(3075):     at java.lang.reflect.Method.invokeNative(Native Method)
12-05 14:55:11.613: WARN/System.err(3075):     at java.lang.reflect.Method.invoke(Method.java:521)
12-05 14:55:11.613: WARN/System.err(3075):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-05 14:55:11.623: WARN/System.err(3075):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-05 14:55:11.623: WARN/System.err(3075):     at dalvik.system.NativeStart.main(Native Method)

谢谢,

1 个答案:

答案 0 :(得分:1)

java.io.FileNotFoundException:http://192.80.62:48080/Services/v0.2.2/SampleService.svc?wsdl

仔细观察:似乎IP地址拼写错误。可能你需要把它改成192.80.62.4:8080?