7

I'm about to write a JSON-web-service (VS Express 2012 - ASP.NET WEB API), and now I want to test it by trying to get the data from my Android-app. So i tried to make my service available for the local network by doing this :

-> changed from localhost to 192.168.1.52 in applicationhost.config

<site name="MyFirstWebApi" id="5">
     <application path="/" applicationPool="Clr4IntegratedAppPool">
         <virtualDirectory path="/" physicalPath="c:\projects\MyFirstWebApi" />
     </application>
     <bindings>
         <binding protocol="http" bindingInformation="*:61802:192.168.1.52" />
     </bindings>
</site>

-> and also changed Project-properties -> Web -> "Use local IIS-Webserver" -> project-url to http://192.168.1.52:61802/

But when I'm now trying to start the service, it gives me an error-messagebox:

The IIS-Express-webserver could not be started (Translated from german)

unfortunatly I can't see what's the exact error, because the VS-output is empty

Anyone know's how to fix that or how to set this up correct?

Andy G
  • 19,232
  • 5
  • 47
  • 69
Postback
  • 619
  • 2
  • 9
  • 27

3 Answers3

7

IIS Express by default does not allow "remote" connections... this post shows you what to do:

IIS Express enable external request

Once you do that, you should be able to connect from ANY other computer in your network.

Also, make sure to open the port in your Firewall.

If that does not work, I would create a site using your local IIS and testing your service that way.

Hope it helps, Daniel.

Community
  • 1
  • 1
Daniel
  • 1,424
  • 1
  • 12
  • 19
  • I guess this would be the best solution, but it give's me an error `Create SDDL failed, Error: 1332 The parameter is incorrect.` Tried with this : `netsh http add urlacl url=http://localhost:8080/ user=everyone` – Postback Sep 08 '13 at 15:38
  • It works fine for me... but some people report that it works when you use quotes around the user name. Like this: `netsh http add urlacl url=http://+:8080/ user="Everyone"` – Daniel Sep 12 '13 at 15:54
3

You could run the scripts to make IIS Express allow remote connections but another option is to use a self-host wrapper for your web api code when testing locally. We had the same issue and started off using this method. Here's how you do it:

Create a new console project and add code like this:

private static void Main()
{

  var config = new HttpSelfHostConfiguration(new Uri("http://localhost:8086"));

  // remove all formatters and only provide json
  config.Formatters.Clear();
  config.Formatters.Add(new JsonMediaTypeFormatter());

  // if needed
  SetupLogging();
  SetupDependencyInjection(config);

  // required for the new Attribute Routing (if you are using it)
  config.MapHttpAttributeRoutes();

  using (var server = new HttpSelfHostServer(config))
  {
    server.OpenAsync().Wait();
    Console.WriteLine("Self Host Server listening on port 8086 ...");
    Console.WriteLine("(You might need administrator privileges)");
    Console.WriteLine("Press Enter to quit.");
    Console.ReadLine();
  }
}

As noted, please run Visual Studio with Administrator rights.

We're using AutoFac for dependency injection which ties into this quite well, see the guide here.

Now run the console project (set as startup project or right click > debug > start new instance).

mjduminy
  • 143
  • 2
  • 7
1

Hi Kindly remove the IP name from ApplicationHost.config.

Create a virtual directory and publish the webservice files.

Set IP Address: - Right click in 'Default Web Site' - Edit Binding - Assign IP address

Restart the IIS.

Browe the 'Default Web Site' It will display with your IPAddress.

Bala
  • 618
  • 5
  • 21