Web roles, endpoints and IIS bindings

You add endpoints to a role in Visual Studio using this editor:

The Service Definition file will be automatically set to this:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="WindowsAzureProject1" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole name="WCFServiceWebRole1" vmsize="Small">
    <Sites>
      <Site name="Web">
        <Bindings>
          <Binding name="Endpoint1" endpointName="Endpoint1" />
          <Binding name="Endpoint2" endpointName="Endpoint2" />          
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="Endpoint1" protocol="http" port="80" />
      <InputEndpoint name="Endpoint2" protocol="http" port="9000" />
    </Endpoints>
  </WebRole>
</ServiceDefinition>

Notice how both endpoints are bound to the website. This results in the website in IIS having bindings set up for both port numbers. However, you can remove the binding, the port will now be free for you to use for whatever you want. The interesting thing is that once un-bound, you can set the protocol to TCP.

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="WindowsAzureProject1" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole name="WCFServiceWebRole1" vmsize="Small">
    <Sites>
      <Site name="Web">
        <Bindings>
          <Binding name="Endpoint1" endpointName="Endpoint1" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="Endpoint1" protocol="http" port="80" />
      <InputEndpoint name="Endpoint2" protocol="tcp" port="9000" />
    </Endpoints>
  </WebRole>
</ServiceDefinition>

This allows you to provision a second site (or application) on an alternative port number on the same box. You would just need to unpack your application and copy it somewhere using a startup task.

This is the command to create a new site in IIS:

appcmd add site /name: sitename /id:2 /physicalPath: %systemdrive%\inetpub\wwwroot /bindings:http/*:9000:MYAPP.cloudapp.net
Advertisements