Задайте вопросЗадайте вопрос
 

ОтвеченоHow do I expose WCF web services in IIS without using .svc files?

  • 17 октября 2008 г. 21:12kainhart Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    I'm currently working on an application which will expose hundreds and possibly thousands of different services through WCF and I'm not thrilled with the idea of creating a .SVC file for each service that I wish to expose through IIS. Are there any ways to dynamically load the set of services that should be served in IIS sort of like how we can do using a WebHandler to serve dynamically generated xml files in ASP.NET.

    Currently I'm having to deal with writing a slew of .svc files and it's another step for our developers ever time we add a new service to our appliation. We are using a custom ServiceHost so that we don't have to write a backing .cs file for each one of these services however it still requires n number of .svc files per ServiceHost. If I can do this dynamically in IIS it would be a big time saver for us and provide a much more managable way of exposing these services.

    By the way, I've searched a lot on this topic and haven't found much other than this other post on the springframework.net forum. Unfortunately it doesn't seem anybody has any bright ideas there yet.

Ответы

Все ответы

  • 6 ноября 2008 г. 2:02kainhart Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    Today I found some interesting details about how Activation works with regard to .svc files in IIS. So far no luck on finding a way to solve my problem but at least these types of resources should help to get a little closer to a possible solution.

    A brief tour of service activation
    http://hyperthink.net/blog/a-brief-tour-of-service-activation/
  • 12 ноября 2008 г. 11:53Lee Witherington Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    Hello kainhart,

    This is very interesting, it is exactly the situation i am in, i have x number of services that are hosted under an IIS7 application that are created dynamically from some metedata within our domain. I have code generated the actual service implementations and interfaces, and were hosting all the services under 1 master service and then using the interfaces to splice the part of the service i wanted e.g (public class MasterService : IPurchasingService, ISalesService).

    This is not acceptable any mroe as the number of serves has exploded and it leaves the client with a really long list of possible proxies, therefore i need to make the services more fine grained (PurchasingService : IPurchasingService, SalesService : ISalesService), which leaves me in the same situation, i have to dynamically create the svc files within the IIS Application directory, or host the services excluding the svc's somehow, Did you manage to acheive this? have you tried the method in your last link?

    very interested in this.

    thanks Lee
    Lee Wivvy
  • 12 ноября 2008 г. 14:21kainhart Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     С кодом
    Lee,

    Thanks for your input. So far I haven't found any acceptable solution. I have however come some materials that suggest that this can be done by either hosting through a traditional ASP.NET Web Application or through WAS in IIS 7 however I haven't seen any specific examples how this would be done.

    The link below to a different post on this forum is what provided me with most of the information that I know at this point.
    http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/4d0c89a1-1d88-4bf3-a3d6-d574cde4b823


    Master Service Pattern

    With regard to the Master Service pattern that you have described above one idea how to make what your doing more maintainable would be to use partial classes to separate out your interface implementations. The following example should apply.

    interface IPurchasingService { // ... } 
    interface ISalesService { // ... } 
     
    partial class MasterService : IPurchasingService { // ... } 
    partial class MasterService : ISalesService { // ... } 

    Unfortunately even though this allows you to use one actual service which implements all of the specified interfaces I still don't see how to expose these ServiceContract individually through IIS without having to make individual .SVC files for each ServiceContract.

    Sales.svc
    <%@ ServiceHost Language="C#" Debug="true" Service="ISalesService" Factory="MyServiceHostFactory" %> 

    Purchasing.svc
    <%@ ServiceHost Language="C#" Debug="true" Service="IPurchasingService" Factory="MyServiceHostFactory" %> 

    I suppose one could expose a single Master Service as shown below and then cast to the desired interface on the client. This should be possible in my case because I'm using the shared contract model however I don't know if this is really the best solution.
  • 12 ноября 2008 г. 14:31Lee Witherington Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     

    My thoughts were also to get an instance of the MasterService, and just narrow the scope by casting down to the specific interface

    ISalesService salesService = new MasterServiceClient();
    etc....

    however these services will be used by otehr external developers, and the architect has stated he doesn’t want the developers to be overwhelmed by 300 or so interfaces and types available on a service, therefore as you also said, i am going to have to create a SVC to represent each interface onto the service
    L

     

    Will let you know if i manage to achieve the *correct* solution. Thanks lee


    Lee Wivvy
  • 12 ноября 2008 г. 14:35kainhart Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     Отвечено
    Lee,

    Just now I found a link that explains one way of solving the same issue by using a ASP.NET VirtualPathProvider. Maybe this methodology would work for us too.

    Dynamic WCF Services (ASP.NET Virtual Paths)
    • Предложено в качестве ответаLee Witherington 12 ноября 2008 г. 14:50
    • Помечено в качестве ответаkainhart 26 ноября 2008 г. 21:10
    •  
  • 12 ноября 2008 г. 14:52Lee Witherington Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    just had a read through, this sounds like the next best thing (best being WCF team would have thoguht of this and provided a better model). Im going to have ago implementing this and provide feedback. (althoguht wont be untill later in the week, got other priority work) :(

    You have been a great help

    thanks lee
    Lee Wivvy
  • 13 ноября 2008 г. 10:51Lee Witherington Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    hello kainhart

    I tried the code in the other post and it works a treat, i refactored a bit to work slighly differently but same concept and all works :)

    However i have now come up against the next issue :(

    Lets say my service has 10 interfaces (representing different orchestrations) two of those interfaces have the same method name, this is fine at design time because the service methods are implemented explicitly "void InterfaceA.OperationA();" but at runtime the service cannot handle this and gives an internl error.

    The way around this is to decarate the service operation contrcts with the name attribute but will have to get cever here because all these are created dynamically. This is not difficult to do but does feel nice, plus the client will not get the simple operation name they will get a concatination of the operation name and something else.

    cheers lee
    Lee Wivvy
  • 26 ноября 2008 г. 21:12kainhart Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    So far the VirtualPathProvider technique mentioned above which was submitted by BinaryCoder seems to be working fine. Of course I also needed to change a few things to fit the goals of my project but the concept of using the VirtualPathProvider to expose virtual .svc files seems to be working like a charm.

    The thing I found interesting was that I needed to use the Global.asax file to initialize my VirtualPathProvider in my WCF Service Application, however from the documentation seems that for projects which are not specifically ASP.NET sites the preference is to use a static AppInitialize method. No matter what I tried the AppInitialize method never seemed to fire for me though so I resorted to using the Global.asax file for now. Furthermore, it doesn't seem possible to add a ASP.NET App_Code folder to my WCF Service Applicatino project. I would have guessed the opposite would have been true.