Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Generate Api for Ionic using NSwag Studio #4798


User avatar
0
BobIngham created

aspnet-core, angular, 5.1.0 Hi Guys, I have spent a long time searching the aspnet-core and angular projects to try find the configuration I need to load into NSwag Studio to generate service-proxy and Dto code from the Zero web Api. I am doing this to create a service proxy file in an Ionic app. [attachment=0:3qfnc0br]Capture.PNG[/attachment:3qfnc0br] I need to know the paths for the .NET assembly path (I think I have this correct), whether I need the app.config or web.config and any additional paths to search for additional files. In a standard .NET Core project I use the dll from the release folder, the config from the root and the .nuget folder from the user folder. I'm not having any luck with Zero.

Help needed generating service proxies for Ionic project anyone?


8 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @BobIngham,

    We use JSON specification for generating service proxies. You can see the json url on the swagger page when you run the host project.

    The NSWAG studio configuration file is under "../angular/nswag/service.config.nswag".

  • User Avatar
    0
    BobIngham created

    @ismcagdas Thanks for the info. I have drawn a blank in getting this to work. I can find the json url, I already had that, I add it to the tab for Swagger Specification. Then, in the tab for Web API Assembly (the one displayed below) I can not get the Load Assemblies button to load anything at all. I have tried to load the contents of service.config.nswag into the JSON Schema tab but I can still not get the Load Assemblies button to generate a list of controllers. Is this something you can help with or am I faced with hand-coding all Api calls from my Ionic project?

  • User Avatar
    0
    BobIngham created

    @ismcagdas Can you point me to any reasonable documentation on how to generate the service proxies/dto's for angular using swashbuckle, nswag, nswag studio etc? I am looking for a tool where I can select the controllers/services for which I wish to generate the code. I have tried NSwag Studio but I can not get it to work with Zero, though I can get it to work with a standard .net core project.

  • User Avatar
    0
    alper created
    Support Team

    I could be missing your point but nevertheless there's this file that updates proxies

    \angular\nswag\refresh.bat
    
  • User Avatar
    0
    BobIngham created

    @ismcagdas, @alper - thanks for the attention, I was looking for hints on how to use swagger to produce service proxy and dto code files. Previously I have used NSwag Studio with success but for some reason I'm not able to get this working with Zero. It's not your job to teach me how to use these tools so I think we can close this one for now and I will cut and paste code from the service-proxies.ts file in the angular project to use in my Ionic project. Not ideal but not a show-stopper either. Again, thanks for your attention, much appreciated.

  • User Avatar
    0
    ismcagdas created
    Support Team

    @BobIngham,

    In AspNet Zero, service proxy generation is done using json specification, not a dll. Because ASP.NET Core controllers are created at runtime, so if you select a dll, NSWAG will not be able to find those controllers.

    I couldn't understand why generating service proxies based on json specification didn't work for you. If you want to filter/not generate some of those controllers for your Ionic app, I think it is not possible right now.

  • User Avatar
    0
    BobIngham created

    @ismcagdas - thanks again, I seem to be always in your debt.... Today I started afresh and instead of building my own config I opened the service.config.nswag file from the ProjectName\angular\nswag folder using NSwag Studio ([https://github.com/RSuter/NSwag/wiki/NSwagStudio])). I changed the HTTP service client to HttpClient for compatibility with Ionic 3 and managed to generate a service proxies file into my Ionic project. It's a little bit verbose given the fact that my Ionic project is basically a data entry device for dynamic forms created in Zero but it allows me access to a lot of functionality I do need such as languages, organization units, security and the like. I would seriously suggest you take a look at Ionic as an alternative to Xamarin. Thanks again.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks for your feedback @BobIngham :). We also upgraded to HttpClient in the latet version but probably your nswag config is one of the previous ones.

    We are trying to follow Microsoft's track when selecting the technologies we use but we will consider other options like React Native and Ionic for the future.