Generate dynamic in memory Web service in .NET

Posted on 2007-07-21
Last Modified: 2013-11-07
1) I'd like to create web services on the fly using reflection.
2) I'd like the web services to be searchable and emit WSDL spec's on themselves like normal web services.
#3) Basically, I want to have my code generate web service functions based on some database data, and create the definitions in memory and expose them on the server.

Is this possible?
Question by:drinkwater
    1 Comment
    LVL 9

    Accepted Solution

    It is but is not the best approach.
    1. You can create on the fly any kind of classes with Reflection, and their associated asmx.
    2. You can query than the .asmx with http://yourserver/yourservice.asmx?WSDL. That will basicaly generate the wsdl and disco
    3. You can run on client wsdl.exe tro have your proxy generated.

    1. Be carefull to NOT use the directories in IIS, the app will restart
    2. You cannot reference the proxies, as their signature may change
    2. Wouldn't be better if you just create simple dll's (the ones that you keep in DB) providing some functionality. Than do a single service called, let's say, "InvokerService" which provides you methods to create objects and invoke their methods (you can even play with their statefull/stateless behaviour, by storing them in Session), and an InvocationResult class to embed the responses, and ensure serializability. Than you may use Assembly.Load, Assembly.Invoke on server side, and you have a fixed proxy on client side that exposes things like:
    GUID objectGUID = InvokerService.LoadOnServer("myclass");
    InvocationResult respose = InvokerService.InvokeMethodOfStatefullObject(objectGUID, "themethod", object[]...)
    or stateless
    InvocationResult respose = InvokerService.InvokeMethod(objectGUID, "themethod", object[]...)

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
    The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now