Two WebServiceHost instances

176 views Asked by At

I am using a library called SwaggerWcf to generate Swagger definitions for my application hosting a WCF REST API. I have finally made it work as I want it with the following code:

  var swaggerHost = new WebServiceHost(typeof(SwaggerWcfEndpoint));
                var endpoint =
                    new WebHttpEndpoint(
                        ContractDescription.GetContract(typeof(ISwaggerWcfEndpoint)),
                        new EndpointAddress("http://localhost/docs"))
                    {
                        AutomaticFormatSelectionEnabled = true,
                        FaultExceptionEnabled = true
                    };

                // required to generate the swagger content
                var e = new SwaggerWcfEndpoint();

                swaggerHost.AddServiceEndpoint(endpoint);

                var apiHost = new WebServiceHost(typeof(RestDataInterface));
                var endpoint2 =
                    new WebHttpEndpoint(
                        ContractDescription.GetContract(typeof(IRestDataInterface)),
                        new EndpointAddress("http://localhost/api"))
                    {
                        AutomaticFormatSelectionEnabled = true,
                        FaultExceptionEnabled = true
                    };


            apiHost.AddServiceEndpoint(endpoint2);

            swaggerHost.Open();
            apiHost.Open();

My question now is: is this the right way of doing it? As you can see I am creating two WebServiceHost instances. One for swagger and one for my actual API. While this seems to work fine, am I missing something? This API is intended to be fast but does not need to handle many concurrent users.

Thank you

0

There are 0 answers