2016-12-02 121 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

回答

相關問題