0
votes

I'm new to the WinRT space.Our company has started developing a windows 8 store app.I initially started doing it in XAML / C# until I realized I can use javascript and html with WINJS ;).

I Have have written a lot of C# code to do calls specifically methods using HTTPClient for REST calls.

1.Will I be able to reuse those methods and call them from my JS? 2.Do I need to re-package them in a class lib or runtime component 3.How do I access these classes in javascript?

Any push in the right direction would be very helpful.

Many thanks.

2
if your app connects to a web service thru rest api, may be you can think of putting a service client wrapper in winrt and use it from view model in js code. - Sushil
Do you have an example of doing this? - vanzylv
as of now, I have not hit the code reuse between c# and JS for my apps. I have written them fully in winjs or c#. hence, i do not have sample code. - Sushil
TRANSLATE c# to javascript: JSIL, scriptsharp, SharpKit, bridge.net, or cshtml5. I don't know whether these work well with WinRT or WinJS, but it is what I would try to do. AFAIK, These solutions are intended to allow you to continue developing in C#, essentially using javascript as the "assembly language" for deployment. (In contrast to a one-time translation from one language to another, as a way to aid porting to a different platform.) - ToolmakerSteve

2 Answers

2
votes

Yes, you need to repackage them. Create a Windows Runtime Component project from file-new project (and not the class library type). When you compile you'll see what you need to fix as there are some restrictions on types.

Classes need to be sealed, can't inherit (except in limited cases) and other restrictions. This project type creates the .winmd (metadata) that can be used by your JavaScript app.

The important note is from here: .NET Framework Support for Windows Store Apps and Windows Runtime

If your component will be used only with C# or Visual Basic, there's no reason to make it a Windows Runtime component. If you make it an ordinary .NET Framework class library instead, you don't have to restrict its public API surface to Windows Runtime types.

0
votes

If you change you C# types to be WinRT types you should be able call them from JS. Here is the MSDN documentation to get you started