Failed to create Azure WebSpace

I am trying to create a new website using the nuget package Microsoft.WindowsAzure.Management.WebSites (Version 3.0.0)

This tutorial was helpful (its Java though): http://azure.microsoft.com/fi-fi/documentation/articles/java-create-azure-website-using-java-sdk/ except that it is suggested to use a constant WebSpaceNames.WestUSWebSpace

...

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 throw an exception: NotFound: Cannot find WebSpace with name westuswebspace.

I really want to create a custom WebSpace.

Also, I cannot find any method for it. See MSDN

So the only way to make this work is to use the existing WebSpace created with the site manage.windowsazure.com

. It defeats the whole purpose of automating it.

The only Create method [...] on IWebSpaceOperations

is CreatePublishingUserAsync

that I tried running too, but that throws an exception This operation is not supported for subscriptions that have co-admins.

, which is very annoying on its own, doesn't make much sense to me, but that's not really the core of my question.

+3


source to share


1 answer


I have resolved this using the preerelease package: PM> Install-Package Microsoft.Azure.Management.WebSites -Pre

This works great. Except that this is only a preliminary release of the reason

// 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 slots for deployment you should consider this: https://github.com/Azure/azure-sdk-for-net/issues/1088

0


source







All Articles