Porting WCF Service Web.config to Windows Service App.config - wcf

I've been working with about a dozen WCF Services that have been deployed to various machines with IIS. All binding/configurations have been kept in the usual "web.config" file that was created to keep the services more configurable and keep the service code itself more clean. However, I've just recently been tasked with creating a Windows Service to host these WCF Services. One question that I have is, do I just copy all the settings from the web.config file to the App.config file for the windows service? Or do I need to reconfigure all the endpoints/bindings/etc. using a different format in the App.config file? I've never created a windows service before and not 100% sure what I need for setup once I've created the Windows Service Host. Thanks in advance.

The WCF configuration elements in web.config should translate directly to app.config. I've cut and pasted web.config elements like this in the past. The only thing to watch out for is that neither web.config nor app.config like certain elements repeating, so if you're merging configuration data from multiple web.config files, you'll have to ensure that you don't repeat sections that should only exist once.

I always thought the .NET config model didn't fit well with WCF service configuration.
There's a way to teach WCF to retrieve its configuration from an alternative location. I like to set it so that the WCF service retrieves its configuration information from ServiceName.config rather than web.config or AppName.exe.config. This solves the problem of repeating elements mentioned by Harper Shelby.
Here's a full explanation and some code.
Using that custom service host, moving a WCF service from IIS to a self-hosted model is really simple.
See also, WCF Configuration - Split it out of app.config

Related

what are the best practices in hosting more than one wcf servicehosts (.svc files) in IIS 7

I have three type of wcf services developped and for which i have created three .svc files like this:
service1.svc
service2.svc
service3.svc
in an asp.net website project.
So how to host these services on the IIS 7?
and what are the best practices in hosting more than one services (.svc) files.?
i saw this link:
Can I have multiple .svc files in one virtual directory under IIS in WCF?
which i know already, so is this the only best practise available.? or i am missing something?
You will need one .svc file to instantiate the ServiceHost for each specific webservice.
However, you will have to look into the IIS specific features like 'Health monitoring', 'Process recycling' etc.
When configurating you services, use relative addressing (i.e. when you expose multiple enpoints using one .svc).
You can check on MSDN how to host WCF Service on IIS using SVC file.
what are the best practices in hosting more than one services (.svc)
files.?
Yes, you can host more than one service on IIS. But If you have N services you need to have N svc files and N service contracts on your web.config.

Deploying Silverlight Business Application

I have a silverlight business application which access to a web service. I've created WCF service (in RIA part) which access this web service, and then added Web service reference in SL project. Using this way (proxy), I got service address like this: localhost:7777/... When I deployed application to IIS, this port number was not the same (expected, but...).
Since I couldn't configure this port number, I made separate service (not in the same solution) and deployed to IIS. After that, I added service reference to SL project. Similar like before, but now service is not in the same solution, but independently deployed on IIS. This approach doesn't work. In Fiddler all I could see is HTTP 500.
Could someone please tell me how to deploy SL Business Application which has an access to a WCF service which is deployed separately?
Best,
Joksimovic
What you'll want to do is create separate versions of your ServiceReferences.ClientConfig file (which resides in your Silverlight application and contains the service endpoints for the application).
We create a separate ServiceReferences.ClientConfig for each possible deployment location and then base them on the Silverlight project's build configuration. So, when the project is built and it's build configuration is set to "Debug", we have a ServiceReferences.Debug.ClientConfig whose contents are copied into the project's local ServiceReferences.ClientConfig. Ditto for our Test, UAT, and Release builds.
Here is a link which talks about choosing the correct config based on your build configuration: How to use Visual Studio 2010 config transform when running/debugging locally?

Wshttpbinding translated to basic

I have a WCF service composed by two projects:
WCF service library
WCF Web application
The First project has a service call IMyService implemented by MyService. It is configured by using WS binding and if I press F5 on this project the WCFTestClient render the WS binding.
In the web app I have an .svc file with this markup with the same name
<%# ServiceHost Language="C#" Debug="true" Service="[Namespace].MyService" %>
If I press F5 on this project it renders a BasicHttpBinding. Same in the Client.
Why?
I have just checked that WCF Service Library project by default creates app.config with WSHttpBinding used for default service. When you run WCFTestClient it always uses this local config. If you want to use WCFTestClient to test additional services you must add their configuration to this config. This config is never used for anything else.
WCF Service application uses web.config. In WCF 4.0 it uses simplified configuration which adds endpoints based on some predefined conditions. By default it adds BasicHttpBinding endpoint to all services exposed over HTTP with common ServiceHostFactory.
How is your config file configure? If you configure the endpoint to use the wshttpbinding, this is the one that should be used.
Would you mind adding some code here (including the binding and endpoint details from the config file), so we could take a look?
Thanks,
Roberto Lopes.
I believe the original question was very poorly posed, to get a satisfactory answer you need to clearly state all the details.
First which version of Visual Studio are yo using? Since nothing is said, I'll assume it's the latest version VS2010 with SP1.
Let's say you have a visual studio solution that has two projects, one is a WCF Service Library, another is a WCF Application, both created using the default project template without any manual tweaking.
The WCF Service Library will have a app.config file with the following line:
in short, Visual Studio 2010 (SP1) uses wsHttpBinding for WCF Service Library projects by default.
The WCF Service Application project, however, will have a web.config file that contains no explicit endpoint definition, in which case, the default endpoint binding used is basicHttpBinding.
The OP said "When I pressed F5 on this project ....", this is a very misleading statement.
What does it mean to "press F5 on a project"? Do you mean you selected the project node in the solution tree, then pressed F5? if that's the case, what happens will always depend on which project is set as the start-up project in the solution (not on which project node is currently selected in Visual Studio UI).
If the WCF Service Application project is the start-up project, pressing F5 will NOT cause the WCF test client to run, instead, it will cause the folder of the project to be displayed in IE.
If the WCF Service Library project is the start-up project, the WCF test client will be run, and this is only because in the debug section of the project's properties window, the start options has the following by default:
/client:"WcfTestClient.exe"

How do I deploy a WCF service library to WAS?

I have created a WCF service library (not a WCF service application).
The project output is a dll.
How can I host this on IIS 7.5/WAS?
I believed that creating a service library was the way to go so that it could be used on a variety of hosts, whereas the service application is limited to IIS.
I'm getting lost in MS mumbo jumbo here, so I'd appreciate any help on getting this service deployed.
Thanks!
Edit
I got the service hosted by following these instructions:
http://msdn.microsoft.com/en-us/library/ms733109.aspx.
It seems like there has to be a better way to host service libraries. Deployment shouldn't require taking settings from app.config and moving them into web.config. Is it standard to wrap them in service applications? Is that even possible?
How are other people handling this?
Yes, creating separate library is good practice because hosting code is not coupled with your services. But you still have to write a host. In WAS, host is in a Web application. To host service in WAS you have to create .svc file and configuration for each service. That is the reason why you have to copy configuration from app.config to web.config. In .NET 4.0 this can be simplyfied with configuration based activation (no .svc is needed) end default endpoints.

Hosting a WCF endpoint with programatic settings in IIS

I need to host a WCF service in IIS that exposes a wsHttpBinding. That part is working nicely using the settings of system.serviceModel in my web.config.
What i need now is to setup the configuration (like maxReceivedMessageSize and other options) through a configuration assembly that is also used by the client(s).
How is this possible? I see no handles in my .svc file like in my client to overload binding configuration. I suspect this is because it is automaticly handled by ISS when the application starts up as in contrast to a windows service where you have to manually declare the client/channel.
Am i right about this? And would the solution to his problem (if i still want hosting inside IIS) to remove all configuration and instead create a HttpHandler that takes care of the hosting on startup?
If i'm right i guess i just wasted a whole lot of space writing this, but i can't help thinking i'm missing something.
You're missing something :)
Create a custom ServiceHost and use that in the .svc file; in the custom service host do all your configuration