title: How to provide RESTful web service(s) from WPF application?
body: <p>Typically a WPF application is a consumer/client of a RESTful service(s) on a web server. I would like to have it reversed - WPF application should be able to expose an web API. This would be consumed by an web app.</p>
  
  <p>The flow:</p>
  
  <pre><code>web app ---sends a command to--&gt; WPF app
  ** WPF app makes a 'long running job' until its user decides to stop **
  WPF app ---passes data back to--&gt; web app
  </code></pre>
  
  <p>The communication should be in Json format. I have prepared <a href="https://swagger.io/specification/" rel="nofollow noreferrer">OpenAPI</a> (in <a href="https://yaml.org/" rel="nofollow noreferrer">YAML</a>) schema for it at the <a href="http://editor.swagger.io/" rel="nofollow noreferrer">http://editor.swagger.io/</a>. In the future it could be used to make changes to the WPF app's web API.</p>
  
  <p>It allows to generate ASP.NET Core server c# code stub. What would be the requirements to run ASP.NET Core server in WPF and weither it would be light weight enough for use?</p>
  
  <pre><code>public static IWebHost BuildWebHost(string[] args) =&gt;
      WebHost.CreateDefaultBuilder(args)
          .UseStartup&lt;Startup&gt;()
          .Build();
  
  // somewhere in the WPF app: BuildWebHost(args).Run();
  </code></pre>
  
  <p>The code is auto-generated by <a href="https://github.com/swagger-api/swagger-codegen" rel="nofollow noreferrer">https://github.com/swagger-api/swagger-codegen</a>.</p>
  
  <p>There is a <a href="https://stackoverflow.com/q/52151412]">post</a> which failed to integrate ASP.NET Core 2.x into WPF application. Unfortunatelly, ASP.NET Core 3.0 and later will only run on .NET Core.</p>
  
  <p>I have some bits here and there but not a working concept. My options could be:</p>
  
  <ul>
  <li>Use a 3rd party framework or library. Should be able to use OpenAPI/YAML schema or Swagger generated server stub code etc.
  
  <ul>
  <li>Could ServiceStack be the missing piece here?</li>
  </ul></li>
  <li>Integrate ASP.NET Core into WPF. Is it is even possible?</li>
  <li>Launch a separate web server (not a self-hosting) with web services from the WPF application. Sounds bad.</li>
  <li>Implement WCF web service(s) and requests.</li>
  <li>...</li>
  </ul>
  
  <p><strong>How to implement the web server/service(s) at WPF side? Maybe there is an existing 3rd party framework which could save me from reinventing the wheel?</strong></p>
  
  <p>PS. There is a similar question <a href="https://stackoverflow.com/q/40979108">how to expose a restful service inside a WPF project</a> but it is outdated.</p>