How to generate id.jwt in Ziti console for C# sample - weather app

Hi @RS_MOB,

I’ve not tried the .NET sdk with xamarin myself, so I don’t know what sort of issues might happen when I try that.

I’ll spend some time and try to make a sample Xamarin app and see how it goes for me…

@RS_MOB, I was updating my environment and looking things over when I found a StackOverflow post indicating that Xamarin was deprecated and leaving support in 2024. Microsoft link to the announcement here.

From that page:

.NET 6 takes over from Xamarin for building Android, iOS, and cross-platform applications. Xamarin.Android and Xamarin.iOS projects should be upgraded to .NET SDK-style projects. Xamarin.Forms projects should be upgraded to .NET Multi-platform App UI (MAUI).

Would an example that uses MAUI be acceptable? I'd like to keep us up-to-date with "current/future" best practices and it sounds like that's MAUI, not xamarin. Let me know please, thanks

@TheLumberjack Thanks for your update.

MAUI is in our roadmap, should take another 6 to 8 months for adoption. Xamarin is our current platform for our mobile application and will continue to use it till Microsoft supports it.

We will wait for your sample Xamarin app

Hi:

Recently, when I try OpenZiti on Ubuntu 22.04, there are two problems I cannot solve.

First:

We want to use the Python SDK in our local simple server-client Python application, we create the two Python codes and after we do this :

pip install Openziti 

We still need the id.json file.
However, I cannot generate the id.json file correctly after several trys. Could you please provide some guidances on Python SDK?

The second problem:

After I found I cannot solve above problem, I was trying to find the similar problem in this forum. Then, I found this C# sample. Everything runs well in the beginning. However, when I try the C# sample:

I got the following error:

ziti-sdk-csharp-main/Samples$ ls
bin                     
HostedService.cs   
OpenZitiSamples.csproj  
SampleBase.cs  
Weather.cs
Enrollment.cs
LoggingHandler.cs  
Program.cs              
setup-scripts
HostedServiceClient.cs  
obj                
Properties              
Util


$ dotnet run OpenZitiSamples.csproj weather
ziti-sdk-csharp-main/Samples/OpenZitiSamples.csproj : warning NU1603: OpenZitiSamples depends on OpenZiti.NET (>= 0.8.339.37518) but OpenZiti.NET 0.8.339.37518 was not found. An approximate best match of OpenZiti.NET 0.8.339.42160 was resolved.
iti-sdk-csharp-main/Samples/OpenZitiSamples.csproj : warning NU1603: OpenZitiSamples depends on OpenZiti.NET (>= 0.8.339.37518) but OpenZiti.NET 0.8.339.37518 was not found. An approximate best match of OpenZiti.NET 0.8.339.42160 was resolved.
ziti-sdk-csharp-main/Samples/Program.cs(8,16): error CS0234: The type or namespace name 'legacy' does not exist in the namespace 'OpenZiti' (are you missing an assembly reference?) [/ziti-sdk-csharp-main/Samples/OpenZitiSamples.csproj]
ziti-sdk-csharp-main/Samples/Program.cs(61,43): error CS0246: The type or namespace name 'ZitiEnrollment' could not be found (are you missing a using directive or an assembly reference?) [/ziti-sdk-csharp-main/Samples/OpenZitiSamples.csproj]

The build failed. Fix the build errors and run again.


$ dotnet run OpenZitiSamples.csproj
ziti-sdk-csharp-main/Samples/OpenZitiSamples.csproj : warning NU1603: OpenZitiSamples depends on OpenZiti.NET (>= 0.8.339.37518) but OpenZiti.NET 0.8.339.37518 was not found. An approximate best match of OpenZiti.NET 0.8.339.42160 was resolved.
iti-sdk-csharp-main/Samples/OpenZitiSamples.csproj : warning NU1603: OpenZitiSamples depends on OpenZiti.NET (>= 0.8.339.37518) but OpenZiti.NET 0.8.339.37518 was not found. An approximate best match of OpenZiti.NET 0.8.339.42160 was resolved.
ziti-sdk-csharp-main/Samples/Program.cs(8,16): error CS0234: The type or namespace name 'legacy' does not exist in the namespace 'OpenZiti' (are you missing an assembly reference?) [/ziti-sdk-csharp-main/Samples/OpenZitiSamples.csproj]
ziti-sdk-csharp-main/Samples/Program.cs(61,43): error CS0246: The type or namespace name 'ZitiEnrollment' could not be found (are you missing a using directive or an assembly reference?) [/ziti-sdk-csharp-main/Samples/OpenZitiSamples.csproj]

The build failed. Fix the build errors and run again.


$ dotnet run OpenZitiSamples.csproj HostedService

... ... same error above

$ dotnet --version
6.0.408

Thank you vert much
Looking forward hearing from you

Can you elaborate on how you tried to make the id and which python sample you're running?

For the C# demo, it seems like our dependency is out of date in nuget somehow. I'll see if I can fix that, thanks for letting us know.

Hi @Nick, I pushed a chang out to main to fix that sample. Do note that the proper way of running it from the Samples folder is by running just dotnet run weather. Thanks for pointing that out

Take a look a this gif I just made and you can watch me run it

weather

Hi:

Thank you for your solution.

However, when I do that, it show following output:

~/Desktop/ziti-sdk-csharp-main/Samples$ ziti edge login 
Using controller url: https://klabzhao:1280/edge/management/v1 from identity 'default' in config file: /home/klabzhao/.ziti/quickstart/klabzhao/ziti-cli.json
Using username: admin from identity 'default' in config file: /home/klabzhao/.ziti/quickstart/klabzhao/ziti-cli.json
Enter password: 
Token: 20d07db3-201d-40e5-bd58-9337a460a6f6
Saving identity 'default' to /home/klabzhao/.ziti/quickstart/klabzhao/ziti-cli.json


~/Desktop/ziti-sdk-csharp-main/Samples$ pwsh setup-scripts/weather.ps1
 
Router list:
  - klabzhao-edge-router
 
Enter the name of the edge router to use for offload from the OpenZiti overlay: klabzhao-edge-router
EdgeRouter identity: klabzhao-edge-router will be used as the router to offload traffic for the demo.
EdgeRouter identity: klabzhao-edge-router already has the expected attribute [weather-svc.binders]. No need to update, skipping.
weather.demo identity exists. Delete and overwrite?: y
delete of identity with id yB6tj9v.P5: OK
creating identity: weather.demo
Looks like the service already exists. Try to cleanup/start again?: y
Cleaning up...
delete of config with id 5byzTXTricLiHtsKvSxCz0: OK
delete of config with id 53hJRiaGKVnHxiRthFzpdZ: OK
delete of service with id 5GvWi147vVb1ruqxVKTL0B: OK
delete of service-policy with id 7FmniOg0jzDUpa95EKaYbN: OK
delete of service-policy with id 5RYpPjF5CFfKzACIG2OlqU: OK
Clean up complete.
New config weather-svc.host.v1 created with id: 46kA8TelbK085NjNSnVooC
New config weather-svc.intercept.v1 created with id: 51ZZKfS1XJaDBVPAzrMx1k
New service weather-svc created with id: 6D2TOIuKNx4qlqofPRXHw3
New service policy weather-svc-dial created with id: fx6qdy41LonWNXZxMYMZ0
New service policy weather-svc-bind created with id: 6vWGaAiInNyrNFSSa9Qwz5
 
=====================================================
Setup for weather.svc is complete                    
If this is the first time running this script, allow 
time for the services to propegate to the router     
before running the sample or you may receive an error
like: no terminators exist for service               

then, execute the sample using: 
  dotnet run weather setup-scripts/weather.demo.jwt 
=====================================================

~/Desktop/ziti-sdk-csharp-main/Samples$ dotnet run weather setup-scripts/weather.demo.jwt
/home/klabzhao/Desktop/ziti-sdk-csharp-main/Samples/OpenZitiSamples.csproj : warning NU1603: OpenZitiSamples depends on OpenZiti.NET (>= 0.8.339.37518) but OpenZiti.NET 0.8.339.37518 was not found. An approximate best match of OpenZiti.NET 0.8.339.42160 was resolved.
/home/klabzhao/Desktop/ziti-sdk-csharp-main/Samples/OpenZitiSamples.csproj : warning NU1603: OpenZitiSamples depends on OpenZiti.NET (>= 0.8.339.37518) but OpenZiti.NET 0.8.339.37518 was not found. An approximate best match of OpenZiti.NET 0.8.339.42160 was resolved.

~/Desktop/ziti-sdk-csharp-main/Samples$ dotnet run weather
/home/klabzhao/Desktop/ziti-sdk-csharp-main/Samples/OpenZitiSamples.csproj : warning NU1603: OpenZitiSamples depends on OpenZiti.NET (>= 0.8.339.37518) but OpenZiti.NET 0.8.339.37518 was not found. An approximate best match of OpenZiti.NET 0.8.339.42160 was resolved.
/home/klabzhao/Desktop/ziti-sdk-csharp-main/Samples/OpenZitiSamples.csproj : warning NU1603: OpenZitiSamples depends on OpenZiti.NET (>= 0.8.339.37518) but OpenZiti.NET 0.8.339.37518 was not found. An approximate best match of OpenZiti.NET 0.8.339.42160 was resolved.

~/Desktop/ziti-sdk-csharp-main/Samples$ 



After above, there is no further output, which should be the weather info.
Do you have an idea about this ?

BTW, all the above codes are running on local Debian machine in a same terminal.

Hmmm. “no output” is definitely unexpected. It looks like the “native” logging isn’t working on this sample.

OpenZiti.Logging.SimpleConsoleLogging(LogLevel.Trace);
OpenZiti.API.NativeLogger = OpenZiti.API.DefaultNativeLogFunction;

Those lines are usually commented out. I’ll dig in a bit more. My guess is that your client isn’t able to connect to an edge router or to your controller and it’s just sitting there never timing out.

I ran from Ubuntu on WSL, I don’t think that would matter and it’s debian-flavored. I’m more troubled the lack of output though. Do you see any logs from your router at all?

After I changed OS to Ubuntu 22.04.2, it becomes better.
However, there is still an error in the last step:
I am not sure if it is the problem in C# code, or it is problem in my configuration:

~/Desktop/ziti-sdk-csharp-main/Samples$ dotnet run weather setup-scripts/weather.demo.jwt
/home/nick/Desktop/ziti-sdk-csharp-main/Samples/OpenZitiSamples.csproj : warning NU1603: OpenZitiSamples depends on OpenZiti.NET (>= 0.8.339.37518) but OpenZiti.NET 0.8.339.37518 was not found. An approximate best match of OpenZiti.NET 0.8.339.42160 was resolved.
/home/nick/Desktop/ziti-sdk-csharp-main/Samples/OpenZitiSamples.csproj : warning NU1603: OpenZitiSamples depends on OpenZiti.NET (>= 0.8.339.37518) but OpenZiti.NET 0.8.339.37518 was not found. An approximate best match of OpenZiti.NET 0.8.339.42160 was resolved.

Strong identity enrolled successfully. File saved to: /home/nick/Desktop/ziti-sdk-csharp-main/Samples/weather.demo.json
Request:
Method: GET, RequestUri: 'https://wttr.in/', Version: 1.1, Content: <null>, Headers:
{
 User-Agent: curl/7.59.0
}

Response:
StatusCode: 503, ReasonPhrase: 'Service Unavailable', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
 Access-Control-Allow-Origin: *
 Date: Wed, 26 Apr 2023 22:42:51 GMT
 Content-Length: 359
 Content-Type: text/plain; charset=utf-8
}

Sorry, we are running out of queries to the weather service at the moment.
Here is the weather report for the default city (just to show you what it looks like).
We will get new queries as soon as possible.
You can follow https://twitter.com/igor_chubin for the updates.
======================================================================================


===============================================================================================

==============================================================
Sample failed to execute: One or more errors occurred. (Response status code does not indicate success: 503 (Service Unavailable).)

  at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
  at System.Threading.Tasks.Task`1.get_Result()
  at OpenZiti.Samples.Weather.Run(String[] args) in /home/nick/Desktop/ziti-sdk-csharp-main/Samples/Weather.cs:line 42
  at OpenZiti.Samples.Program.Main(String[] args) in /home/nick/Desktop/ziti-sdk-csharp-main/Samples/Program.cs:line 26
==============================================================

Is there anyone meet this output:

Sorry, we are running out of queries to the weather service at the moment.
Here is the weather report for the default city (just to show you what it looks like).
We will get new queries as soon as possible.
You can follow https://twitter.com/igor_chubin for the updates.

I think, it means the application build is correct, just the weather service from “wttr.in” not available, right ?

OR, it is my building problem ?

Yeah that’s what happens when they service too many requests. If you’re getting that response, it worked! As for debian, I wonder if you had a firewall enabled that ubuntu didn’t have enabled?

Looks like it worked!