3

I am designing a web app which has two UI - one a traditional web page(HTML views) and one a WPF app. I know that in order to have a Seperation of concern its best to design as shown below as in, a Web API that is consumed by a MVC app and a WPF app.

enter image description here

However I am a time crunch and I am wondering if I can get away with having just a traditional MVC design as below. Also I may have a lot more non-CRUD operations which if I were to go WebAPI ,will have to implement as RPC style, adding to complexity(more work,more time) of the webAPI.

enter image description here

My only question is - can a MVC action be consumed in a WPF app? And if yes, do I need to use any special API to do so as mentioned in this post or will the new HttpClient package suffice?

Community
  • 1
  • 1
superartsy
  • 489
  • 1
  • 11
  • 27

1 Answers1

1

Yes a WPF application, just as any other application that is able to send HTTP requests and receive responses, is able to consume an ASP MVC controller action.

After all, ASP MVC framework just parses URLs, deduces routes information (area, controller, actions, parameters and so on), and finally invokes the associated action with parameters before sending you an HTTP response.

From MSDN :

In contrast, user interaction with ASP.NET MVC applications is organized around controllers and action methods. The controller defines action methods. Controllers can include as many action methods as needed. Action methods typically have a one-to-one mapping with user interactions. Examples of user interactions include entering a URL into the browser, clicking a link, and submitting a form. Each of these user interactions causes a request to be sent to the server. In each case, the URL of the request includes information that the MVC framework uses to invoke an action method.

So even a simple HttpClient would be enough to interact with an ASP MVC controller action. But you can also use a framework or library of your choice that help you to build HTTP requests and/or to transform HTTP responses into something more suitable for your application.

It's not mandatory but it could make save some time!

That being said, beware of all scenarii requiring authentication, it could get things harder :

  • If you need forms authentication, then you can to retrieve your auth cookie first, and then include it in future HTTP requests (see this post for more information)
  • If you need windows authentication, then you have to provide your credentials (see this page from asp.net website)
Community
  • 1
  • 1
AirL
  • 1,887
  • 2
  • 17
  • 17
  • could you clarify what you mean regarding authentication scenarios? – superartsy Oct 14 '13 at 14:54
  • I have updated my answer with a little more details about authentification cases. – AirL Oct 14 '13 at 15:30
  • What is the authentication is going to be handled by a third party agent - Siteminder for example. – superartsy Oct 14 '13 at 19:13
  • As far as i know, third party authentication usually works with tokens that have to be included in HTTP request headers. And HttpClient API enables you to add header fields. Never having dealt with Siteminder, i don't know exactly what it is expecting? Maybe you will find some hints in here : http://social.msdn.microsoft.com/Forums/en-US/4435ea55-4609-4122-8aae-5b34abe00c42/use-of-siteminder-tokens-in-wcf-to-authenticate-against-siteminder. – AirL Oct 15 '13 at 11:10
  • And as it seems that we are drifting to another topic, pershaps it could be interesting to create a new question about it. Thus, you would increase your chances to get a better and more detailed answer ;) – AirL Oct 15 '13 at 11:21
  • Agree. Another post much needed. – superartsy Oct 15 '13 at 13:38