none
Convert WCF services to ASP.NET web api RRS feed

  • Question

  • Hi all,

     I've got a few hundred services exposed using wcf (custom binding, self-hosted, no IIS) , we have a new client that wants to access some of the services and use json

     For that I used wcf rest using WebHttpBehavior and the service is consumed using RestSharp on the client side.

     The services are not RestFul and this is not mandatory.

       I'm currently using ServiceHost class and adding end points by: 

     endPoint = host.AddServiceEndpoint(implementedContract, new WebHttpBinding() { CrossDomainScriptAccessEnabled = true }, new Uri(serviceAddress));
    endPoint.Behaviors.Add(new WebHttpBehavior() { DefaultOutgoingRequestFormat = WebMessageFormat.Json, DefaultOutgoingResponseFormat = WebMessageFormat.Json });

    From what I could read the new asp.net web api is based on mvc, does this mean that I no longer expose interfaces like I did in wcf? (I still didn't had much time to read about asp.net web api)

    Is there a direct way to expose services via asp.net web api without changing my host completely?

    Thanks for all the help,

    Luis Pinho


    • Edited by LPinho Tuesday, September 24, 2013 5:48 PM
    Tuesday, September 24, 2013 5:47 PM

All replies

  • Hello Luis,

    From your question I do not understand why you want to move to webapi?  It sounds like you are accomplishing your requirements with self-hosted json wcf services.

    To answer your questions, yes you expose the services differently as you are in building upon a framework (MVC).  In practice you might find it is very simple to expose your existing contracts via apicontrollers.  I would imagine the most difficult technical issue might be around security. 

    If you are only talking about just exposing json services, then moving these into MVC does not give you anything over the wcf approach (ignoring the benefits of IIS as you can host your services in IIS).  If you are also going to host some related pages written in MVC, then things are different.

    Oh, and yes there is a way to expose the services via asp.net without changing your host.  You simply expose your services via .svc files in the iis application.  Also, IIS is really just a service so, though I don't recommend this as I feel it increases maintenance (re., more lines of code), you could create your services on application start in the global.asax file.

    So many ways to expose json services.  Anyway, food for thought...


    Jeff

    Tuesday, September 24, 2013 11:23 PM
  • Hi Jeff,

     I would like to thank you for your support, these are not common problems.

     I'm already using a custom security with headers because the original solution was made for Silverlight that also lacked (in its early versions) support for many security options that existed in wcf

     There are two things that annoy me a bit about my current setup.

     1st, the problem I'm having that you're helping me with (described at http://social.msdn.microsoft.com/Forums/en-US/e596830e-55fe-4037-9e05-1313975d7438/webhttpbehavior-adding-this-behavior-slows-down-end-point-creation-from-less-than-one-second-to-a).

     2nd, the json encoding used by wcf rest is not 100% compatible with the open source clients (I'm developing the cross platform client application for android, ios and windows phone with mono/Xamarin).

     I'm trying to understand the 1st problem with your help :), and with the second problem I was able to use custom encoding with json.net but then mono kicked me out with lack of support for the solution that I had, that worked well in .net.

     So, I was trying to prepare for the future just in case the 1st problem doesn't have any solution.

    Thanks again for your reply, I think that, for now, I will focus my attention in solving my 1st problem.


    Luis Pinho

    Wednesday, September 25, 2013 8:48 AM
  • Hi Luis,

    As other members have mentioned, ASP.NET Web API and WCF REST or standard service have different programming model. Therefore, there is no straight means to directly reuse or convert a WCF service to ASP.NET web api format. We might need to redefine the data types and operation signature so as to follow the ASP.NET web api's syntax.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, September 26, 2013 5:24 AM
    Moderator
  • Hi Steven,

     thanks for your reply, I understood that, since I've got a few hundred services, that is not possible for me.

     Unfortunately I've got the problem I describe here: http://social.msdn.microsoft.com/Forums/en-US/e596830e-55fe-4037-9e05-1313975d7438/webhttpbehavior-adding-this-behavior-slows-down-end-point-creation-from-less-than-one-second-to-a

     If you have the change, and since you're a MSFT maybe you could help me with that problem, that, for me, is a bit of a blocking point. 

    Thanks for the support


    Luis Pinho

    Thursday, September 26, 2013 8:59 AM
  • Hi,

    For your question in: http://social.msdn.microsoft.com/Forums/en-US/e596830e-55fe-4037-9e05-1313975d7438/webhttpbehavior-adding-this-behavior-slows-down-end-point-creation-from-less-than-one-second-to-a

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Best Regards,
    Amy Peng


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, October 1, 2013 2:50 AM
    Moderator