0

I have started in the last few weeks working (or trying it) Simple MVC-App for notifications.

I used this example and established iP-tunnels ot localhost with ngrok.(see sample & content page below). https://learn.microsoft.com/de-de/learn/modules/msgraph-changenotifications-trackchanges/5-exercise-change-notification

https://github.com/microsoftgraph/msgraph-training-changenotifications/tree/live

If I run only on app locally at same time all is fine but if I will start a 2nd Notification App it failed with this message

System.IO.IOException: Failed to bind to address https://127.0.0.1:5001: address already in use. ---> Microsoft.AspNetCore.Connections.AddressInUseException: Normalerweise darf jede Socketadresse (Protokoll, Netzwerkadresse oder Anschluss) nur jeweils einmal verwendet werden.

I tried some changes in ngrok.yml file but without access too.

# Create 3 tunnels, each for different ports, with only https enabled
# This way the ngrok process stays bellow the Free plan limit (4 tunnels)

authtoken: **************************
log: ngrok.log
tunnels:
  first:
    addr: 5000
    proto: http
    #host_header: localhost
  second:
    addr: 5000
    proto: http
    #host_header: localhost

I tried to change the url in the appsetting.json but it doesn't work:

{
    "Logging": {
      "LogLevel": {
        "Default": "Debug"
      }
    },
    "AllowedHosts":"*",
    "MyConfig": {
    "AppId": "****************",
    "AppSecret": "*********************",
    "TenantId": "********",
    "Ngrok": "https://76bd76a6aca4.ngrok.io"
  }
}

But after starting the first app the 2nd crashed on exceptions. Then I tried to use ports 5000 m 5010 and so on and changed the settings in launchsetting.json but I failed again.

"msgraphapp": {
  "commandName": "Project",
  "launchBrowser": true,
  "launchUrl": "api/values",
  "applicationUrl": "https://localhost:5001;http://localhost:5000",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"

Please can someone tell me what I must do, so that I can start 2 or more apps running on localhost and tunneled with ngrok or an alternative.

ingo_ww
  • 171
  • 1
  • 13
  • Out of curiosity, why do you need to run two instance for the same app and have an Ngrok tunnel for each while working with Graph Change Notifications? – Danstan Aug 25 '21 at 08:47
  • @danstan: not the same app a similar app for notifcation a webhook for other subcribing to another resource. do really differnet GUID not the same but i need different apps to handle diufferent noticatiobns. ANd best case it would possible to do it locally the same pc. i change the title again to make it more clear. – ingo_ww Aug 25 '21 at 10:42
  • @danstan; Independent from my actual problem with callrecord notification, it is an normal case to that one appn is runnung dor afew uswer for logging and testing. And if then there is needed a short testing of another app locally could happened sometimes. yes on complete different apps it is no problem to use the same tunnel. But URL/api/notifications is fix by microsoft so they URi is not changeable if I am not wrong. – ingo_ww Aug 25 '21 at 10:51

1 Answers1

0

You must have followed Exercise - Azure AD apps .NET core web APIs. To have tow apps running and exposing two Ngrok tunnels for graph change notifications

First configure your ~/.ngrok2/ngrok.yml like below. Notice the different ports.

authtoken: ****...***
tunnels:
  first:
    addr: 5000
    proto: http
  second:
    addr: 5010
    proto: http%

Second edit each of your apps properties to have different set of http and https bind ports. See the screenshot below showing settings on launchSettings.json for each file.

This way you should be able to run two .net apps with each having Ngrok tunnel for MS graph.

Remember to have the right Ngrok url added to each appSettings

enter image description here

Danstan
  • 1,501
  • 1
  • 13
  • 20
  • Happy to help, Try to setup like the screenshot and see if it works. You can still engage in the comment to get better understanding. Consider accepting and upvoting the answer if it solves your case to help other folks. – Danstan Aug 25 '21 at 11:45
  • Thanks,I did mostly the same stuff and it worked for the first app. i didn'T took multi-tenant, I only selected single-tenant. And i am not sure babout these steps: * dotnet add package Microsoft.Identity.Client * dotnet add package Microsoft.Graph * dotnet dev-certs https --trust I think i forgot the last step but i seems to work. the adddr:5000 in ngrok.yml i changed 1st to 5001 and then 5010 (becuase lauchsetting for https used 5001) I wrote it that i tried this. And I tried change the "applicationUrl" but it worked not. I used same app reg fror 1 apps. Could this a problem? – ingo_ww Aug 25 '21 at 11:48
  • I dont think so. Each app (even if the appid is the same instance) will start with the `applicationUrl` it is given and process notifications according to the `Ngrok` url it is give. As long as the .net app instances run on different ports and have Ngrok urls tunneling to the respective ports, it should work. – Danstan Aug 25 '21 at 11:55
  • sorry 1 comment is to short: in ngrok.yml you used port 1st:5000 and 2nd: 5001 but in launchsettings.json you used 5000,5001 for the 1st and for the 2nd 5010,5011. I s that a copy paste error ? I tried both yesterday , without change in launchsettings.json to 5010 it crashes and changeing tro 5010,5011 there was another exception on start. I hope i can try this example you posted soon and see if s.th was wrong in my builds. – ingo_ww Aug 25 '21 at 11:58
  • `ngrok.yml` use 5000 and 5010, `launchsettings.json for app1` use https://localhost:5011;http://localhost:5010, `launchsettings.json for app2` use https://localhost:5001;http://localhost:5000 – Danstan Aug 25 '21 at 12:04
  • :Can you please correct your the code block in your answer. I think can test what you wrote tomorrow morning. today i have other things to do first today I will post the results then, i hope it work and i made a stupid error on my tryings. – ingo_ww Aug 25 '21 at 13:59
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/236410/discussion-between-danstan-and-ingo-ww). – Danstan Aug 25 '21 at 14:43