3

I'm trying to create a new Website using the nuget package Microsoft.WindowsAzure.Management.WebSites (Version 3.0.0)

This tutorial has been helpful (even though its Java): http://azure.microsoft.com/fi-fi/documentation/articles/java-create-azure-website-using-java-sdk/ except it suggests to use the WebSpaceNames.WestUSWebSpace constant.

var hostingPlanParams = new WebHostingPlanCreateParameters
{
    Name = this.webhostingPlanName,
    NumberOfWorkers = 1,
    SKU = SkuOptions.Free,
    WorkerSize = WorkerSizeOptions.Small
};
var result = new WebSiteManagementClient(this.Credentials)
    .WebHostingPlans
    .CreateAsync(WebSpaceNames.WestUSWebSpace, hostingPlanParams, CancellationToken.None)
    .Result

This will result in an exception: NotFound: Cannot find WebSpace with name westuswebspace.

I actually want to create a custom WebSpace.

Except I can't find any method for it. See MSDN

So the only way I can make this work is using an existing WebSpace, that had created through the manage.windowsazure.com site. Which defeats the whole purpose of automating this.

The only Create[...] Method on IWebSpaceOperations is CreatePublishingUserAsync which I have tried running this as well but it results in an exception This operation is not supported for subscriptions that have co-admins. Which is pretty annoying in itself, doesn't make much sense to me, but is not really the core of my question.

Sam7
  • 3,382
  • 2
  • 34
  • 57
  • 1
    did you ever figure out a solution? I presume, like me, your ultimate goal is to programmatically create and publish to a website, which requires this weird webspace thing that can only seem to be created, like you mentioned, through the management portal :( – mo. Jun 30 '15 at 18:39
  • 1
    @mo I added my solution below – Sam7 Jun 30 '15 at 23:48

1 Answers1

0

I resolved this by using the prerelease package: PM> Install-Package Microsoft.Azure.Management.WebSites -Pre Which works perfectly well. Except that it's only a pre-release of cause

// Create Web Hosting Plan
var hostingPlanParams = new WebHostingPlanCreateOrUpdateParameters
{
    WebHostingPlan = new WebHostingPlan()
    {
        Name = "WebHostingPlanName",
        Location = "Australia Southeast",
        Properties = new WebHostingPlanProperties
        {
            NumberOfWorkers = 1,
            Sku = SkuOptions.Standard,
            WorkerSize = WorkerSizeOptions.Small
        }
    },
};
var result = this.ManagementContext.WebSiteManagementClient.WebHostingPlans.CreateOrUpdateAsync(
        "ResourceGroupName",
        "WebHostingPlanName",
        CancellationToken.None).Result;

// Create Website
var websiteParams = new WebSiteCreateOrUpdateParameters
{
    WebSite = new WebSiteBase
    {
        Location = "Australia Southeast",
        Name = "WebSiteName",
        Properties = new WebSiteBaseProperties
        {
            ServerFarm = "WebHostingPlanName"
        }
    }
};

var siteResult = this.ManagementContext.WebSiteManagementClient.WebSites.CreateOrUpdateAsync(
        "ResourceGroupName",
        "WebSiteName",
        null,
        websiteParams,
        CancellationToken.None).Result;

If you want to use deployment slots you have to take this under consideration: https://github.com/Azure/azure-sdk-for-net/issues/1088

Sam7
  • 3,382
  • 2
  • 34
  • 57
  • What version are you using? Based on the date of your post I thought it was 4.4.2 but the WebHostingPlanCreateOrUpdateParameters class is not there. I am in NuGet hell. – Snowy Feb 25 '16 at 15:39