使用Web API和Windows Phone合作 [英] Work with Web API and Windows Phone

查看:194
本文介绍了使用Web API和Windows Phone合作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个,它由两部分组成的解决方案:一个Web服务器,它出版的一些REST服务和移动客户端,消耗这些服务。
为了实现REST服务,我已经使用的Web API技术。

I am developing a solution that is composed of two elements: a web server, which publishes some REST services, and a mobile client, which consumes those services. To implement the REST services I have used the Web API technology.

当我在调试启动web项目,一切工作正常。 63954 / API:我可以通过指向本地主机使用的服务。一个奇怪的事实:如果我把localhost与127.0.0.1或与机器,192.168.xxx.xxx的LAN地址,服务器不回答了。

When I start the web project in debug, everything works fine. I can use the services by pointing to localhost:63954/api. A weird fact: if I change "localhost" with "127.0.0.1" or with the LAN address of the machine, 192.168.xxx.xxx, the server does not answer anymore!

然后,当我启动了Windows Phone客户端,它运行在一个虚拟仿真器,它无法连接到Web服务器!即使两个部件在相同的机器上运行。
显然,在Windows Phone的我不能使用本地主机,因为手机的本地主机是手机本身。所以我想用192.168.xxx.xxx地址这是正在运行Web服务的计算机的地址。但手机模拟器无法达到web服务。

Then, when I start the Windows Phone client, which runs in a virtualized emulator, it fails to connect to the web server! Even if the two components are running in the same machine. Obviously, in Windows Phone I cannot use the "localhost", since the localhost of the phone is the phone itself. So I'm trying to use the 192.168.xxx.xxx address which is the address of the machine that is running the web service. But the mobile phone emulator fails to reach the webservice.

我需要在Visual Studio 2012中运行Web服务器,因为我需要调试它,并使它从Windows Phone模拟器可到达的,但我不知道该怎么做。你可以帮我吗?任何想法?

I need to run the Web Server in Visual Studio 2012, since I need to debug it, and to make it reachable from the Windows Phone Emulator, but I do not know how to do it. Can you help me? Any idea?

感谢你这么多,
    里卡尔多。

Thank you so much, Riccardo.

编辑:按照此处找到的链接( IIS绑定防爆preSS到一个IP地址),并通过关闭我的防火墙,我可以运行在Web应用程序之外VS12,我可以把它从其他电脑访问网络中,因此也从WP模拟器。这可能是一个变通办法,但我不能用这种方法调试REST服务VS,这是不好的... ...

By following the link found here (Binding IIS Express to an IP Address) and by turning off my firewall I can run the web application outside VS12 and I can make it reachable from other pc in the network, and so also from the WP emulator. This could be a work-around, but I cannot debug the REST service in VS in this way and this is not good...

推荐答案

正如你所提到的Windows手机运行在客户端机器seprate,解决这个问题的方法之一是,绑定你的机器的IP地址到Web API,所以在Web API可使用本机的IP address.You可以通过使用Microsoft WebMatrix中绑定IP地址的项目进行访问。
因此,您可以访问使用IP address.Hope这可以帮助Web API。

As you mentioned the windows phone is running seprate in your client machine,One way of solving this problem is ,Binding your machine's Ip address to the Web Api,SO the Web api can be accessed using the Machine's Ip address.You can Bind the ip address to the project by using Microsoft Webmatrix. So,You can access the web Api using the Ip address.Hope this helps.

这篇关于使用Web API和Windows Phone合作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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