Dynamically generate #ServiceHost directive / Dynamic SVC files - wcf

I am using Castle Windsor's WCF facility to host my services.
This means that my .svc files only contain this one line:
<%# ServiceHost Service="MyService" Factory="Castle.Facilities.WcfIntegration.DefaultServiceHostFactory, Castle.Facilities.WcfIntegration"%>
Now instead of having 10 .svc files for 10 services, I thought it would be nice to have just one generic file.
Something like Generic.svc?service=MyService that would automatically generate the correct #ServiceHost directive, maybe with URL rewriting in addition, so that I could write MyService.svc, but it would get rewritten to Generic.svc.
Any thoughts on this?
I don't want to move away from IIS and host the services myself.
Thanks!

Related

Deploy WCF Service on IIS6

I have an WCF RESTFull Service which i need to deploy on IIS6. I have never done this before and i am completely new to the IIS environment. I found a good solution here on the forums but its not precise enough for my case. maybe someone can give me based on this solution a more expanded version:
Option 1 - "bin" deploy (preferred option)
compile your WCF service into a DLL (class library)
create a website in IIS6
copy the WCF DLL's into the website's .\bin folder
create a *.svc file in that website
add an appropriate web.config in the website folder to define your endpoints and service configuration etc.
Your WCF service will now be reachable at the website's base address, plus the name of the *.svc file, e.g.
http://myserver/someweb/Myservice.svc
Your *.svc would look something like this:
The Service= attributes denotes the class implementing the service - fully qualified with its namespace.
What is the .\bin folder in point 3. ? Where can I find it?
I need the exact settings for the property page tabs of the website please. Also the address: http://myserver/someweb/Myservice.svc ... What is the someweb ? the physical directory of the website? or the base address from the webconfig file?
An exact step for step guide with all needed settings would be great.
For the '/bin', manually create it in the root of the website you create and copy the assemblies into it.
Create the .svc in the root of the website and access it using a similiar url to;
http://yourwebsitename/service.svc

WCF in IIS 5.1 served as plain text file

I just set up a simple WCF service on my dev environment, and so far the endpoints are working OK, for both SOAP and JSONP requests.
I've proceeded to deploy this solution to a staging server hosted on IIS 5.1 (old, I know, but bear with me), and the .svc files suddenly aren't working anymore. Not that IIS can't find them, but rather they're getting served as plain text files.
This is basically what shows up on my browser when I pop in an .svc file:
<%# ServiceHost Language="C#" Debug="true" Service="service.myservice" CodeBehind="myservice.svc.cs" %>
Now I've tried all the solutions I've seen around SO and other sites (including reinstalling the ASP.NET binds on IIS using aspnet_regiis and reinstating the WCF ISAPI handles using servicemodelreg.exe), but none of them work.
One quirk that may be of note is that the IIS 5.1 is serving off port 8000, because Apache is currently running on the default 80. Could this be a culprit? I've tried running servicemodelreg -s:myservice to try to hit my app path squarely, but it tells me that there's no such application on IIS:/localhost/myservice (maybe because it's supposed to be on IIS:/localhost:8000/myservice? I'm not sure.)
I've verified that I've got a functional .NET 3.5 framework down, the .aspx files are served OK. It's just the .svc files that aren't getting served properly.
Any ideas?
If servicemodelreg hasn't worked, check that the .svc is set up with an ISAPI mapping.
Go to the Home Directory tab on the properties of your web site, select Configuration...
If .svc isn't present in the list, set it up with the following parameters:
Executable: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
Extension: .svc
Limit to: GET,HEAD,POST,DEBUG
Script engine: Ticked

wcf client configuration

I have wcf client. It uses .NET 3.5.
When I compile the client I get two files:
client.exe and
client.exe.config.
The second file contains configuration for the wcf client.
In my case I need to prevent the user sitting on the computer to see the urls and change some other parameters from the config file.
So the requirements are, the end user not to see and modify the data stored in the config. The config file contains the same data as app.config. I need to forbid the person using the program to see the end point urls so easy.
Also I have a lot of configuration there so I do not like to code in the moment.
Is there any solution for the problem (embedded app.config of something else)?
Edit: I do not need configurable options. The config file is automatically created when adding service reference from the studio.
Regards
You can also create your proxies programatically instead of using the service reference feature.
Every parameter in the serviceModel config section can be represented in code as well.
The ChannelFactory class will help you create proxies to the service.
You can easily encrypt entire parts of your config files - and not just web.config in web scenarios, but also application config's in stand-alone apps.
Check out some resources on how to do this:
Encrypting web.config values
Encrypting passwords in .NET app.config file
Encrypting the app.config file for Winforms application

Hosting WCF services

I have been working on a Silverlight app that consumes a WCF service. [on Visual Studio]
as a matter of simplicity I created a WCF service in the project itself [as-in I didnt host it in IIS, but let the build-in webdev server in VS do it for me]
It works well, now I want to deploy it on IIS 7.0, can you tell me If i would need to host the service independently and then the remaining stuff or if I just publish the website, the service would be hosted too and the Silverlight client would be able to communicate with the service.
Please help!
Thanks
You basically need
a virtual directory in IIS 7
a SVC file (service file) that instructs IIS how to instantiate your service
You basically have three options to deploy your service implementation:
you can put your service implementation into the code-behind file of the SVC file - that would be my least favourable option - basically don't do it - it gets messy and offers no benefit
you can put your service class file (the MyService.cs file) and the interface file (IMyService.cs) into the App_Code directory (if you're using a Web Site project type) - again, I don't particularly like this approach
your best option: put your service contract (the interface) and your service implementation into a separate class-library assembly for that service, and deploy that MyService.dll into the .\bin directory below the virtual directory where your SVC file lives.
Then add a *.svc file (pure text file) to your virtual directory, which contains:
<%#ServiceHost language="c#" Debug="true" Service="MyService" %>
And of course, you need the appropriate web.config entries - but I'm sure you already have those, right?
Your service address now is:
http://YourServer/VirtualDirectory/YourService.svc
For more info, see How to: Host a WCF Service in IIS
Marc got you the how. In response to your question around need, you will both need and want to separate the services from the Silverlight assets (static references and XAPs). This might not make a lot of sense for smaller sites but as you grow in size this affords you the opportunity to locate your Silverlight assets on a location separate from your services (such as a content distribution network) so that they can be delivered to users as fast as possible.

my wcf services only show directory listing and no wsdl

I have a few wcf services created a number of ways.
all of them only display the directory listing when i browse to them.
(I fixed the part about authentication)
Also I have very nice mex settings for all of them as well.
it seems to me that there should be a file in the service location to browse to?
its especially annoying that I can't display a wsdl file despite the mex settings.
oops...
all i had to do was browse to one of the service files.
like... any file ending in .svc
well, dumb stuff happens