Step 3. Add the Code to Provision a Site

Note: When using the code below, change the values, such as username and password, to match your setup.

  1. In your main function, add the following code:

    // Part 1: Set up connection information for the Web Service

    HostingWS w = new HostingWS();

    w.Url = "http://myserver.myisp.com/epwhostingws/hostingws.asmx";

    w.Timeout = 100000; //time out in milliseconds, -1 implies infinite

    // Part 2: Create the site object for the new site

    Site site = new Site();

    site.DisplayName = "mysite.com"; // Provide required site name

    site.Name = "mysite.com";

    site.ShortName = "mysite.com";

    site.TemplateName = "Default Template";

    // Specify the template using which the site has to be created

    site.ContactEmail = "blackhole@ensim.com";

    site.AdminUserName = "admin";

    site.AdminDisplayName = "Administrator";

    site.AdminPassword = "ensim123";

    //Provide a password or the provisioning will fail

    site.AdminEmail = "user@example1.com";

    //Specify site administrator email address

    site.IpBased = true;

    // Specify if site will be IP based

    site.IpSelection = "auto";

    // Specify IP address manually or 'auto' for automatic IP allocation

    // Part 3: Call the Web Service (page 1)

    w.AddSite(site, "admin", "ensim123");

    //Where 'admin' is the service provider/Reseller username and

    //'ensim123' is the password

    Console.WriteLine( "Created site:mysite.com");

  2. Build the project and run it.
  3. Log in to the service provider control panel, and verify that the site appears on the list of sites.

Code Details

Part 1. Set Up Connection Information for the Web Service

Provide the connection information, which is passed to the Web Service in all API calls made in the header for the request.

Part 2. Create the Site Object for the New Site

The created site object sets the short name, name, and other required information for the site. When working with objects like this, you are simply constructing proxy objects. At this point nothing is being sent to the Web Service.

Part 3. Call the Web Service

This is the only place that the Web Service is called. The Provisioning Service (w) is the Web Services object. If the call fails, an exception is thrown.