4b0
4b0

Reputation: 22323

"physicalDirectory" and "Port" in .csdef file

I try to run my website in window azure.I test locally.My .csdef file looks like:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="Test.Azure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2012-10.1.8">
  <WebRole name="TestWebApplication" vmsize="Small">
    <Sites>
      <Site name="Web2" physicalDirectory="F:\MyPath\">

        <Bindings>
          <Binding name="Endpoint2" endpointName="Endpoint2" />

        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="Endpoint2" protocol="http" port="8080"></InputEndpoint>

    </Endpoints>
    <Imports>
      <Import moduleName="Diagnostics" />
    </Imports>
  </WebRole>
</ServiceDefinition>

When I hit F5 and run project its run successfully.But in browser I saw its take a port 8081.Which is main cause to fail to load a page.

Port 8081

If manually correct a browser url and type port :8080 which is in .csdef file its successfully open a page.Why Loading page take :8081 port.Thanks.

Upvotes: 0

Views: 429

Answers (1)

astaykov
astaykov

Reputation: 30903

It gets little complicated to explain, and to fully understand it, you shall have relatively good understanding of IIS and site bindings, but let me try.

First, the Windows Azure Compute Emulator. You can get a basic picture of a Windows Azure Deployment from my blog post here. Basically you have a load balancer exposed to the public, with its public IP Address (VIP) and some public ports opened. Then you have you role instances, each one of which do have its own IP Address (DIP) and port opened to listen requests coming from Load Balancer.

Windows Azure Compute emulator has replicated this whole structure locally. It has software emulated Load Balancer, and it creates virtual IP Addresses (separate) for each instance of your Role(s). Then it exposes the "load balancer" on local address 127.0.0.1 and port, which is not being used by any other process. It then creates a separate WebSite in IIS (or IIS Express) for every instance (given the role has only one site defined). Each site is bound to its own unique IP Address and its own port on that IP Address. The emulated load balancer then round robins the traffic received on 127.0.0.1 to the underlying role instances (in our case - the different sites).

Now, when you edit the "Sites" section in your CSDF file you are creating a custom sites + binding information for the IIS. There is one standard and well know name for site, and it is Web. If there is a site definition with name Web, it is bound to wildcard domain in IIS. All requests from 127.0.0.1 on the emulated load balancer are only redirected to the Web Site which was defined with the name Web. Well, the "Web" site has to be a Web Application, and has to be the project which is associated with the WebRole. In your case, you are defining Web2. This will work, but the following limitations:

  • You have to explicitly provide hostHeader attribute value when you define the binding.
  • When you debug locally, you have to manually map whatever value you provided in hostHeader to 127.0.0.1 in your hosts file (located in %windir%\system32\drivers\etc\hosts - file without extension, can only be edited by Administrator).
  • When you hit F5, after browser loads something with error on 127.0.0.1, you have to manually type the custom value you had in hostHeader but keeping the custom port the Browser opened.

Only then, your browser will properly load the site.

The fact that your websites opens fine, when you type in port :8080 shows nothing more but a direct access to the website, skipping the local load balancer emulator.

If you want to fully test in an emulated environment a web site project, you have to go through the process I described. If you do not want to bother with the stuff, you can just launch your Web Site directly and debug it. But if you do so, you will not get access to RoleEnvironment variables and configuration settings.

Upvotes: 1

Related Questions