Minimum Configuration for a WCF service to host - c#

I have a class library project which has an interface and an implemented service class with Service and Data Contracts.
I have built those to dlls and now I have created an empty web application and referenced those assemblies. I want this web application to host the service.
What minimum Web configurations do I need to make the service up and running.

Related

NLog not working from Windows Service hosted WCF Service

I have a WCF service with NLog logging in C#. This service references 3 class libraries. Every projects uses NLog logging.
In Debug mode everything works fine, every projects logs to the specified log file successfully. I use async file target.
In production mode I have a Windows Service that hosts the above WCF Service. This Windows Service contains the NLog package too.
After I install my Windows service I see only log messages from Windows Service and not from the WCF Service and the other class libraries.
How can I receive log messages to file from WCF Service after it's hosted by a Windows Service?
Thank you!

How to debug a web service in Visual Studio

I have to make some changes to a Web Service which is currently in production.
There is a project (a class library) called Accounts.WebServer which is a container project, it's Global.asax initializes a WCF service as an instance of the web service class.
My question is how can I run the web service (container project or project containing the web service) locally? I try and run the container project through VS2015 and I get a lot of IIS errors, one I fixed by adding
<validation validateIntegratedModeConfiguration="false"/>
to the web.config
But I am still unable to get the web service to run. Once it is running I should be able to see a page which lists the operations exposed, and see sample data to pass to the operations.

How to expose restful interface from windows service ?

I wrote a wcf service that expose restful interface.
Now i using the iis as the wcf service host.
There are some action that i need to make on my application beside the exposing of the restful - and for this need i must run my application as a windows service.
But the using the iis as a host will not make my wcf server run as a service.
How to make it possible to using a windows service with expose wcf restful interface service ?
You can self-host WCF services, please refer to ServiceHost.
To be able to run the app in 2 different host models, you have to separate hosting stuff from you main code. The key point of it: you can use controllers created in the other library project.
I did this before:
Create a library project and move all you controllers and other classes there.
Create empty WFC service, add reference to the lib above and make it working.
Create an empty console app, reference to the lib, add self hosting stuff and make it working.
Add topshelf package to console app to be able to install it as windows service.
So you will get:
building and deploying WCF project you can host it in IIS;
building a console app you can run it as console app;
using topshelf install param you can install a console app as windows service.

Service reference works for windows form but doesn't work for class library

I have two applications. One of them is a windows forms application and other one is a web application which use a class library. I use a web service(WCF). When I give this web service as service reference to my windows form application everything is fine. But when I give it as service reference to class library, I have this error 'No connection could be made because the target machine actively refused it ...'
I give the reference as the same way to these two projects. What should I do?
By default, you cannot configure your WCF service through a configuration file coming from your class library.
Add a web.config with the proper WCF configuration (similar to the one in the app.config of your winforms project) in your web application assembly.

Combining WCF Service Library and WCF Service Application

Thanks to Stack Overflow and a few other sites, I understand the difference between the WCF LIbrary and WCF Service Application templates.
Briefly the Library is a DLL that allows for multiple types of hosting. It does not have a .svc file. While the Service Applications template is created specifically with IIS in mine with a .svc file.
I read that WCF Service Library is the best way because it is the most flexible. But I NEVER see instructions on how to do it apart from using the WCF Service Application template.
Is it difficult to go from WCF Service Library to hosting on IIS from scratch? I have two books on WCF and I've read numerous articles and none of them cover how to create a svc file using only the WCF Service Library and No WCF Service Application. Why?
Nigel Shaw also mentions on the following link that there are limitations to using the Library option. What is the purpose of WCF Service Library?
Basically What I want to do is host the WCF Service on both IIS and a Windows Service. Thus it appears that the combined way is the best way. Nevertheless, I'm trying to learn why there aren't more instructions on using the WCF Service Library.
Ok, I did find a couple of articles that seem to use an ASP.NET Web Application and tells you how to create a text file for the svc file.
This article: http://debugmode.net/2010/12/25/wcf-service-library-creating-hosting-and-consuming-wcf-service-with-wcf-service-library-project-template/
and this one: http://danielvanwyk.wordpress.com/2010/04/30/create-host-and-consume-a-wcf-service-using-the-wcf-service-library-template-in-visual-studio-2008/
But what I still don't understand is why is the ASP.NET Application still needed? And If i add a svc file does it get placed in the wwwroot directory (that seems to be where the WCF Service Application places it .svc file?
Thanks!
A WCF Service Library has to be hosted in order to be used - you can host it in IIS, a Windows Service or some self-hosted option (like a console app, WinForm, WPF, etc).
In the last two links you provide, they're demonstrating how to host the library in an ASP.NET service application, but you don't have to use that project template to host it. It's simply one option out of several.
You can create an IIS-hosted implementation of your class library without using a VS project template, but you'll need to manually add the .svc file and the Web.config. I have done this several times:
Create a folder (I normally put mine in the wwwroot folder of inetpub, but you can put it wherever you desire).
Create a bin folder in the folder you created in step 1, and put the WCF service library and any other required assemblies in it.
Add a .svc file with the appropriate markup in the folder created in step 1.
Add a Web.config with the appropriate service model configuration in the folder created in step 1.
Create an application in IIS that points to the folder you created.
Now you have an IIS-hosted instance of your service. You can then use another copy of the WCF service library for your Windows-Service hosted instance.

Categories

Resources