Home > Blockchain >  Share types/models from service reference to client
Share types/models from service reference to client

Time:09-17

I am developing a blazor webassembly program with a web api backend. The backend uses a WCF service reference. How can i share the types/models generated by the WCF service reference with the webassembly program?

CodePudding user response:

You could try to create the client proxy in a different project. I don't remember any options in VS, you may have to use the command line tool.

But I wouldn't.

The generated code usually isn't the prettiest, with lots of metadata, dependencies and properties you don't need or want in your SPA.

So consider writing a layer of DTO classes in a shared project and use AutoMapper to convert the data.

DTOs are Data Transfer Objects, the shared code between Client and Server. In your Client you can use them as Models and/or ViewModels.

  • Related