WCF在Android项目(FileNotFoundException异常)使用 [英] WCF used in Android Project (FileNotFoundException)

查看:130
本文介绍了WCF在Android项目(FileNotFoundException异常)使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中的简单的Web服务。
这里是C#code:

I have a simple web service in c#. Here is the C# code :

IService1.cs

IService1.cs

[ServiceContract(ConfigurationName = "IService")]
    public interface IService1
    {
        [OperationContract]
        [WebGet]
        string TestAndroid();
    }

Service1.svc.cs

Service1.svc.cs

public class Service1 : IService1
    {
        public string TestAndroid()
        {
            return "Test done !";
        }
    }

下面是Android code:

Here is the Android code :

protected Boolean doInBackground(String... urls) {

        try {

            URL url = new URL("http://10.0.2.2:49363/Service1.svc/TestAndroid");

            InputStream in = new BufferedInputStream(httpURLConnection.getInputStream());

            BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));

            String line = reader.readLine();

            reader.close();

        } catch(Exception e){
            return false;
        }
        return null;
    }

当我想读的InputStream的,我有一个错误。

When I want to read the InputStream, I have an error.

这是

java.io.FileNotFoundException:
   http://10.0.2.2:49363/Service1.svc/TestAndroid

java.io.FileNotFoundException: http://10.0.2.2:49363/Service1.svc/TestAndroid

我不知道哪里出了问题,因为当我在浏览器中去,我有

I don't know where is the problem, because when I go in browser I have

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Test done !</string>

有人能帮助我吗?

Can someone help me ?

推荐答案

我希望你的服务是工作,你已经通过调用URL的 http://10.0.2.2:49363/Service1.svc/TestAndroid
我说得对不对?

I hope your service is working and you had tested it on your computer by invoking url http://10.0.2.2:49363/Service1.svc/TestAndroid Am I right?

您的问题那么简单的解释将是你的Andr​​oid不知道IP地址10.0.2.2。

Then simple explanation for your issue would be that your Android doesn't know about ip address 10.0.2.2.

你能确认这是访问?刚刚尝试在浏览器中打开相同的URL在Android设备上。

Can you validate that is accessible? Just try to open the same url in browser on your Android device.

简单的解决方案,看看这个IP地址 - 您的手机应该是在同一个WiFi与您的计算机

Simple solution to see this IP address - your phone should be on the same WiFi as your computer.

更新:
目标是看电脑服务运行WCF主机。问题是 - 可以在Android设备看到WCF主机?

Update: Goal is to see computer with service running WCF host. Question is - can Android device see WCF host?

相反的方向是不相关的,但它是很好的了解,
Android模拟器不能从计算机看到。这是很好的<一个href=\"http://stackoverflow.com/questions/3010130/is-there-an-easy-way-to-setup-the-android-emulator-to-access-the-lan-of-the-host\">explanation

The opposite direction is irrelevant but it's good to know that Android emulator cannot be seen from the computer. Here is good explanation

这篇关于WCF在Android项目(FileNotFoundException异常)使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆