2016-12-02 122 views
0

我已经在本地主机上使用IIS发布了我的Restful WCF服务。我可以从我的系统上的任何浏览器访问此Web服务,使用url http://localhost/mobservice/MobSrv.svcandroid studio无法连接到本地主机WCF服务

getCityList是webGet方法在此服务中返回城市列表。我在Android Studio上完成了这项服务。但是,在我的Android程序它显示错误:

java.io.FileNotFoundException:http://10.0.2.2/mobservice/MobSrv.svc/getCityList

我的Android代码如下:

String serviceUrl="http://10.0.2.2/mobservice/MobSrv.svc/getCityList"; 
URL urlToRequest = new URL(serviceUrl); 
urlConnection = (HttpURLConnection) 
urlToRequest.openConnection(); 
int statusCode = urlConnection.getResponseCode(); 
    if (statusCode == HttpURLConnection.HTTP_UNAUTHORIZED) { 
     // handle unauthorized (if service requires user login) 
    } else if (statusCode != HttpURLConnection.HTTP_OK) { 
     // handle any other errors, like 404, 500,.. 
    } 
InputStream in = new BufferedInputStream(urlConnection.getInputStream()); 

的StatusCode返回值404,和的URLConnection .getInputStream()如上所述给出异常java.io.FileNotFoundException

ADB集成已在android Studio中启用。

+0

其中节目的线示出它的例外。你能否提供你得到的异常层次结构信息? – SachinSarawgi

+0

我编辑了一些细节。 – Admin

+0

@SachinSarawgi我GOOGLE了一下,才知道,要访问本地主机使用10.0.2.2,但它不工作 – Admin

回答

相关问题