0

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.

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!

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.

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.

EDIT: 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...

Community
  • 1
  • 1
  • Why is your port 93564? TCP doesn't support anything over 65535 – Filip Apr 20 '13 at 09:19
  • VisualStudio2012 choose a random port and I made a mistake while copying the port... The true port is 63954. I'm sorry for the mistake and thank you Filip to have spotted this. – Riccardo Cipolleschi Apr 20 '13 at 15:05
  • allright. Can you open the 192.168.xxx.xxx address from the browser? What happens when you do? – Filip Apr 20 '13 at 15:09
  • No.. When I do that I receive a message that says: "The webpage cannot be found". I get the same message if I use 127.0.0.1 instead of localhost. And this is very weird to me... EDIT: The error code is HTTP 400 Bad Request – Riccardo Cipolleschi Apr 20 '13 at 17:28
  • when you run `nslookup 127.0.0.1` in the win command prompt, what does it return? – Filip Apr 20 '13 at 17:33
  • After the edit: HTTP 400 means your API is accessible, but there is a problem with the actual request, which is funny, considering the problem is URL-sensitive. See this article http://www.asp.net/web-api/overview/testing-and-debugging/tracing-in-aspnet-web-api . Set up your logging and you'll see what's wrong. – Filip Apr 20 '13 at 18:00
  • 1
    Thank you for your help. Anyway, it does not bring to a solution. If I type nslookup, I get: Name: localhost Address: 127.0.0.1 I have implemented the tracer and I have tried to debug. But when I try to reach the WS through 127.0.0.1 or throught the corresponding 192.168.xxx.xxx address, the tracer does not log anything. It seems that the requests does not reach the server. I have tried to use a Firefox REST plugin to test the service and I get the following message: Bad Request - Invalid Hostname HTTP Error 400. The request hostname is invalid. – Riccardo Cipolleschi Apr 21 '13 at 07:13
  • that is unfortunate, but at least now you have a proper error message. First, try and examine your hostfile ( https://en.wikipedia.org/wiki/Hosts_%28file%29 ). Your nslookup seems fine, but look anyway. Second, try this http://stackoverflow.com/questions/4831097/bad-request-invalid-hostname-iis7 – Filip Apr 21 '13 at 11:20

2 Answers2

0

The Windows Phone 8 emulator works as a separate machine on your network, with it's own IP address and configuration. Therefore, for the emulator to be able to access your service you will need to make sure that the port you are trying to access is open for inbound connections.

Den
  • 16,686
  • 4
  • 47
  • 87
  • I know that the emulator is a different machine. Actually, I have developed other solutions with Windows Phone and a Java web service, hosted on Tomcat Apache. In all of those projects, I do not have any issue with the WindowsPhone-REST pair. So I think that I'm missing some configuration in Visual Studio 2012. I cannot understand why localhost works (from a browser) and why 127.0.0.1 or the corresponding 192.168.xxx.xxx addresses does not... – Riccardo Cipolleschi Apr 20 '13 at 17:32
0

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.

Coder
  • 1