Hosting a class library as WCF RRS feed

  • Question

  • User-25455931 posted


     I happened to go through some code which I have to work upon in near future.

    There a project of output type class library has been created and it has a class structure like below:

    Project Name : MyProjMain

    public class TestController : ITestService
     public OutClass Post([FromBody]InClass objectInClass)
      return objOfTypeOutClass;
    public Interface ITestService
      OutClass Post(InClass objectInClass);
    public class InClass
     public string arg1 {get; set;}
     public string arg2 {get; set;}

    Now I use another project named 'MyProjSelfHost' in same solution to self-host above project.

    I use System.Web.Http.SelfHost for self hosting and do something like this:

    var baseUrl = "someUrl";
    var config = new HttpSelfHsotConfiguration(baseUrl);
    //SomeCode to set config.DependencyResolver
    //Some code to set config.Routes.MapRoute(arguments)
    HttpSelfHostServer server = new HttpSelfHostServer(config);

    After running MyProjSelfHost executable project once the self-hosting is done I use XMLHttp object with xml argument like below to hit the url of hosted service:

    <arg1> SomeStringArgument1 </arg1>
    <arg2> SomeStringArgument2 </arg2>

    I am getting the expected response.

    Now I need to host the project MyProjMain using IIS. This project is of output type class library. It does not have any 'app.config' or 'web.config' file, so I don't think this is a WCF type of project. Now how can I host this project on IIS to fulfill same purpose without changing code of this project. I am allowed to write some wrapper code or add some additional project.

    Please help.

    Thanks in advance!!!

    Thursday, October 10, 2013 3:31 AM


  • User-742633084 posted

    Hi Ashutosh_Pan,

    If I understand correctly, your current code is using custom application to self-host an ASP.NET web api service (see reference below):

    #ASP.NET Web API

    #Self-Host a Web API (C#)

    if you want to host it in IIS, you need to put it in an ASP.NET web application. web api service is naturally packaged with ASP.NET MVC application. However, you can also host it in traditional web form application as well. You can take a look at the articles in the following links and try moving your existing service code into an ASP.NET web app:

    #How to host your web API.

    #Using Web API with ASP.NET Web Forms



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 11, 2013 3:59 AM
  • User-488622176 posted

    Nice question. I think you're understanding the logic of services and WCF.

    In your web project, perform these actions:

    • Add a random new WCF service
    • Add a reference to your class library
    • Open the ".svc" file in edit mode
    • Change the reference to the service interface and service implementation class to the namespace of your service interface and implementation class

    Open the web.config in the IIS project and adjust the bindings as required

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 11, 2013 4:07 AM

All replies