在本地主机的 android 应用程序中使用 Web 服务 [英] Consuming a web service in an android application in localhost
问题描述
我正在尝试使用我从 Android 应用程序在本地创建的 Web 服务.我的问题是,在我的 Android 应用程序中,在某个时刻,我必须提供一个带有如下参数的 URL:http://localhost:8080/CalculatorApp/CalculatorWSService/add?i=1&j=1
I am trying to consume a web service that I created locally from an Android application. My problem is that in my Android app, at a certain point, I have to give an URL with parameters that looks like this : http://localhost:8080/CalculatorApp/CalculatorWSService/add?i=1&j=1
其中 CalculatorWS
是我使用的 web 服务,add
是其中的操作,i
和 j
是 add
操作的参数.现在,我正在使用示例应用程序计算器(来自 NetBeans)进行测试,我想检索正确的 URL 以提供给我的 Web 服务客户端(Android 应用程序),以便它可以返回一个 XML 进行解析.
where CalculatorWS
is the web service I use, add
is the operation in it and i
and j
are parameters of add
operation. For now I am using a sample app Calculator (from NetBeans) for testing and I want to retrieve the correct URL to give to my web service client (Android app) so it can give me back an XML to parse.
我尝试使用上面提到的那个 URL,但它不起作用.
I tried to use that URL mentioned above but it doesn't work.
有人知道正确的网址是什么吗?
Does anybody know what is the correct URL to put ?
推荐答案
您需要将 URL 设置为 10.0.2.2:portNr
you need to set URL as 10.0.2.2:portNr
portNr = ASP.NET 开发服务器的给定端口我当前的服务正在运行本地主机:3229/Service.svc
portNr = the given port by ASP.NET Development Server my current service is running on localhost:3229/Service.svc
所以我的网址是 10.0.2.2:3229
so my url is 10.0.2.2:3229
我已经通过这种方式解决了我的问题
i'd fixed my problem this way
我希望它有帮助...
这篇关于在本地主机的 android 应用程序中使用 Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!