WireMock.Net icon indicating copy to clipboard operation
WireMock.Net copied to clipboard

How to deploy WireMock in Azure ?

Open waqaskhan540 opened this issue 3 years ago • 16 comments

I have deployed WebApplication example of WireMock using Azure App Service , but I am not sure what should be the URL and Port of server , because ports 443 and 80 are already being used by the application itself and I am not sure what URL I can run the wiremock server on within the Hosted Service?

Could you please provide a tutorial on how to deploy WireMock in Azure or is there a better way to deploy it in Azure?

waqaskhan540 avatar Jan 22 '21 16:01 waqaskhan540

The link to the example app in the wiki page was wrong. I did correct this. See https://github.com/WireMock-Net/WireMock.Net/tree/master/examples/WireMock.Net.WebApplication.NETCore3

When you run WireMock.Net as an WebApp in Azure it should just listen at 80 and 433

StefH avatar Jan 22 '21 17:01 StefH

Yes that's correct, but I am not able to get it working, I deployed first with the same configuration settings but got no response.

I am deploying directly from Visual Studio using the publish wizard to Azure App Service, the WebApp is deployed at say following URl https://wiremockwebapp2211.azurewebsites.com , but it gives the following error in browser

HTTP Error 500.37 - ANCM Failed to Start Within Startup Time Limit Common solutions to this issue: ANCM failed to start after 120000 milliseconds Troubleshooting steps: Check the system event log for error messages Enable logging the application process' stdout messages Attach a debugger to the application process and inspect For more information visit: https://go.microsoft.com/fwlink/?LinkID=2028265

I tried with following settings even, but got same response

 _settings = new WireMockServerSettings
                    {
                        Urls = new[] {"http://+:80","https://+:443"},
                        UseSSL = true,
                        StartAdminInterface = true,
                        AdminUsername = _config.AdminUsername,
                        AdminPassword = _config.AdminPassword,
                        ReadStaticMappings = true,
                        AllowPartialMapping = true,
                        WatchStaticMappings = true,
                        WatchStaticMappingsInSubdirectories = true,
                        FileSystemHandler = new CustomFileSystemHandler(_config.MappingsFolder)
                    };

waqaskhan540 avatar Jan 22 '21 18:01 waqaskhan540

I just built that example project and published to Azure, and it works fine. image

Settings are: image

StefH avatar Jan 22 '21 18:01 StefH

Thanks, its working now.

waqaskhan540 avatar Jan 25 '21 15:01 waqaskhan540

OK

StefH avatar Jan 25 '21 15:01 StefH

I am really struggling to get this working. I want to achieve the same as your screenshot - WireMock responding to URLs hosted in an Azure Web App with SSL.

I have copied the sample from here and tried various configurations:

1) With SSL

"WireMockServerSettings": {
    "StartAdminInterface": true,
    "AllowPartialMapping": true,
    "Urls": [
      "http://+:80",
      "https://+:443"
    ],
    "UseSSL": true
  }

Which fails to start the app and produces this error:

Unhandled exception. WireMock.Exceptions.WireMockException: Service start failed with error: One or more errors occurred. (Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.

2) Without SSL

  "WireMockServerSettings": {
    "StartAdminInterface": true,
    "AllowPartialMapping": true,
    "Urls": [
      "http://+:80"
    ]
  }

Which again fails to start the app, but this time with the error:

Unhandled exception. WireMock.Exceptions.WireMockException: Service start failed with error: One or more errors occurred. (An attempt was made to access a socket in a way forbidden by its access permissions.)

  1. Without any URL/Port specified:
  "WireMockServerSettings": {
    "StartAdminInterface": true,
    "AllowPartialMapping": true
  }

This time the app doesn't fail to start, but the response returns a 404, but not from WireMock. Presumably this is because WireMock itself is not listening on port 80. I'm lead to believe this because when I run this locally with this configuration, I can see WireMock chooses a random port by writing this to the console:

        var urls = string.Join(',', _server.Urls);
        
        _logger.LogInformation($"Listing on {urls}");

What am I missing in order to get Wiremock to listen on the same port as the Azure Web App and use SSL?

davemasters1984 avatar Apr 04 '22 08:04 davemasters1984

I noticed you've re-opened this, which I'm grateful for. Don't suppose you have any insights on where I'm going wrong?

davemasters1984 avatar Apr 14 '22 13:04 davemasters1984

@waqaskhan540 I don't suppose you could share what you changed to get it working? As far as I can tell I have exactly the same as the sample application apart from I'm running dotnet 6 not dotnet core 3.1

davemasters1984 avatar Apr 22 '22 10:04 davemasters1984

@davemasters1984 it was a while ago I was working with WireMock, but as far as I remember I didn't change anything, I just published the sample and worked fine for me.

waqaskhan540 avatar Apr 22 '22 14:04 waqaskhan540

Thanks for replying! Do you remember whether you specified 80/443 in the config? The sample app doesn't have any port config, but for me this just causes Wiremock to listen on a random port, but specifying 80 in config gives the error: "An attempt was made to access a socket in a way forbidden by its access permissions"

It's driving me nuts 😭

davemasters1984 avatar Apr 22 '22 14:04 davemasters1984

Hello @davemasters1984,

I did use the https://github.com/WireMock-Net/WireMock.Net/tree/master/examples/WireMock.Net.WebApplication.NETCore3 as an example.

And I published this application via VS 2022 via right click to a Windows App Service plan. image

And it runs fine at https://wiremocknetwebapplicationnetcore3.azurewebsites.net/

In Azure there are no specific config settings: image

The deployed web.config looks like:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!--
    Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
  -->
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\WireMock.Net.WebApplication.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" forwardWindowsAuthToken="false" hostingModel="OutOfProcess" />
  </system.webServer>
</configuration>
<!--ProjectGuid: e1c56967-3dc7-46cb-a1df-b13167a0d9d4-->

And more information why this all works fine, see this post https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications-with-IIS which describes in detail how port 80/443 can be used on IIS/Azure when using a .NET Core application.

StefH avatar Apr 28 '22 21:04 StefH

Hello @davemasters1984, did you manage to get it running on Azure using the above details?

StefH avatar Jun 09 '22 19:06 StefH

Hello @davemasters1984, did you manage to get it running on Azure using the above details?

StefH avatar Aug 25 '22 06:08 StefH

@StefH @waqaskhan540 @davemasters1984 Thanks for sharing knowledge in this thread,

I have followed the same https://github.com/WireMock-Net/WireMock.Net/tree/master/examples/WireMock.Net.WebApplication.NETCore3

My launch settings JSON same as an above sample project, My web. config same as an above sample project.

I deployed on Azure and tried hitting the endpoint but it's getting timed out,.

Then I tried to set up _a setting like below

_server = WireMockServer.Start(new WireMockServerSettings
            {
                Urls = new[] { "http://+:80", "https://+:443" },
                UseSSL = true,
                StartAdminInterface = true,
                AdminUsername = _settings.AdminUsername,
                AdminPassword = _settings.AdminPassword,
                ReadStaticMappings = true,
                AllowPartialMapping = true,
                WatchStaticMappings = true,
                WatchStaticMappingsInSubdirectories = true,
            });

But I got an error "HTTP Error 500.30 - ANCM In-Process Start Failure"

Could you please share your thoughts...

Thanks, Elango

Elangopalakrishnan avatar Aug 25 '22 07:08 Elangopalakrishnan

@Elangopalakrishnan

What kind of App Service Plan are you using?

BTW: I'm using a S1: 1 - Windows plan.

StefH avatar Sep 19 '22 05:09 StefH

Try not setting the ports in the config. That’s what worked for us.

mattisking avatar Sep 19 '22 22:09 mattisking

@StefH

Thanks for replying!

I've created an Azure web app with S1: 1 - Windows app service plan,

I deployed the web app and got startup error I didn't create any custom domain and TSL/SSL certs in Azure. (doubt that this is causing the issue)

And I'm getting below error only on Azure

Application '/LJ/WVC/1310713/ROOT' with physical root 'C:\home\site\wwwroot\' hit unexpected managed exception, exception code = '0xe0434352'. First 30KB characters of captured stdout and stderr logs:
info: wiremockapp.WireMockService[0]
      WireMock.Net server starting
Unhandled exception. WireMock.Exceptions.WireMockException: Service start failed with error: One or more errors occurred. (Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust.

Could you pls have a look 🥲? Thanks!

Elangopalakrishnan avatar Sep 21 '22 22:09 Elangopalakrishnan

I am glad that I have solved this for myself. I am using a B1 App service plan with Linux. Not sure if this will be relevent to the solution but just fyi.

It was quite simple to fix. I just had to use port 8080 for WireMockServerSettings Port setting. No SSL or any urls to set.

I've found this by looking at the docker container logs which you can find in App Service Advanced Tools. You can download the Current Docker logs.

This is a sample of what is in the log and how I've found this.

2022-09-23T08:40:17.347Z INFO  - docker run -d -p 9072:8080 -p 1727:50050 -p 3716:50051 --name ***********************_0_b86148d4 -e WEBSITE_SITE_NAME=*********************** -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=***********************.azurewebsites.net -e WEBSITE_INSTANCE_ID=3402e0d8150eb05fd320284813169fb478bde1d29cbccb4d22c05e1c1bdddd23 -e WEBSITE_USE_DIAGNOSTIC_SERVER=True appsvc/dotnetcore:6.0_20220826.8.tuxprod  

2022-09-23T08:40:17.348Z INFO  - Logging is not enabled for this container.
Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2022-09-23T08:40:20.062Z INFO  - Initiating warmup request to container ***********************_0_b86148d4 for site ***********************
2022-09-23T08:40:35.516Z INFO  - Waiting for response to warmup request for container ***********************_0_b86148d4. Elapsed time = 15.4538701 sec
2022-09-23T08:40:50.627Z INFO  - Waiting for response to warmup request for container ***********************_0_b86148d4. Elapsed time = 30.5653753 sec
2022-09-23T08:41:05.877Z INFO  - Waiting for response to warmup request for container ***********************_0_b86148d4. Elapsed time = 45.8149471 sec
2022-09-23T08:41:20.980Z INFO  - Waiting for response to warmup request for container ***********************_0_b86148d4. Elapsed time = 60.9181091 sec
2022-09-23T08:41:36.075Z INFO  - Waiting for response to warmup request for container ***********************_0_b86148d4. Elapsed time = 76.0134733 sec
2022-09-23T08:41:51.172Z INFO  - Waiting for response to warmup request for container ***********************_0_b86148d4. Elapsed time = 91.1096132 sec
2022-09-23T08:42:06.252Z INFO  - Waiting for response to warmup request for container ***********************_0_b86148d4. Elapsed time = 106.1906026 sec
2022-09-23T08:42:21.336Z INFO  - Waiting for response to warmup request for container ***********************_0_b86148d4. Elapsed time = 121.2744208 sec
2022-09-23T08:42:36.417Z INFO  - Waiting for response to warmup request for container ***********************_0_b86148d4. Elapsed time = 136.3548407 sec
2022-09-23T08:42:51.534Z INFO  - Waiting for response to warmup request for container ***********************_0_b86148d4. Elapsed time = 151.4719374 sec
2022-09-23T08:43:07.247Z INFO  - Waiting for response to warmup request for container ***********************_0_b86148d4. Elapsed time = 167.1853571 sec
2022-09-23T08:43:22.342Z INFO  - Waiting for response to warmup request for container ***********************_0_b86148d4. Elapsed time = 182.2797011 sec
2022-09-23T08:43:37.444Z INFO  - Waiting for response to warmup request for container ***********************_0_b86148d4. Elapsed time = 197.3823346 sec
2022-09-23T08:43:52.542Z INFO  - Waiting for response to warmup request for container ***********************_0_b86148d4. Elapsed time = 212.4801552 sec
2022-09-23T08:44:07.631Z INFO  - Waiting for response to warmup request for container ***********************_0_b86148d4. Elapsed time = 227.5687722 sec
2022-09-23T08:44:10.668Z ERROR - Container ***********************_0_b86148d4 for site *********************** did not start within expected time limit. Elapsed time = 230.6063983 sec
2022-09-23T08:44:10.705Z ERROR - Container ***********************_0_b86148d4 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2022-09-23T08:44:10.713Z INFO  - Stopping site *********************** because it failed during startup.

So if you have a look at the docker run command, it is running the container and binding with these ports. And at the bottom, it is complaining that it cannot ping on port 8080 because nothing is listening on that port.

btw, the site would be still accesable on https since this is set on the the App Service and then it just forwards the requests to the running instance of your app in docker.

adeel41 avatar Sep 23 '22 10:09 adeel41

@adeel41 Thank you for reply!

Yes, It got worked for me as well 😇

I'm using the B1: Windows app service plan.

image

Thank you for your guidance @StefH @adeel41 and @mattisking 😊

Elangopalakrishnan avatar Sep 25 '22 01:09 Elangopalakrishnan

Hi,

Sorry to open this again, the .net core example is working for me but since it's reaching end of support I wanted to upgrade to .NET 6. I set the port to 8080 but am getting Unhandled exception. System.IO.IOException: Failed to bind to address http://[::]:8080: address already in use. This is a Linux app service and B1 plan.

Thanks

kamilb-pg avatar Oct 25 '22 13:10 kamilb-pg

@kamilb-pg

I think the settings should be like:

"WireMockServerSettings": {
        "StartAdminInterface": true,
        "Urls": [
            "http://localhost"
        ]
    }

I've updated example project here: https://github.com/WireMock-Net/WireMock.Net/tree/master/examples/WireMock.Net.WebApplication.NET6

And added some images to the wiki https://github.com/WireMock-Net/WireMock.Net/wiki/WireMock-as-a-(Azure)-Web-App

StefH avatar Oct 25 '22 15:10 StefH

Hi, Deploying the https://github.com/WireMock-Net/WireMock.Net/tree/master/examples/WireMock.Net.WebApplication.NET6 as is in azure, I am still getting the below error HTTP Error 500.37 - ASP.NET Core app failed to start within startup time limit Common solutions to this issue: ASP.NET Core app failed to start after 120000 milliseconds Troubleshooting steps: Check the system event log for error messages Enable logging the application process' stdout messages Attach a debugger to the application process and inspect For more information visit: https://go.microsoft.com/fwlink/?LinkID=2028265

Using app service plan S1.

Any help is appreciated.

shilpamurthy88 avatar Mar 14 '23 14:03 shilpamurthy88

I am not able to run wiremock with same port as my web app on IIS. Please elaborate a bit on the solution

priyankas0907 avatar May 16 '23 05:05 priyankas0907