none
Dynamic WCF Service OperationContract RRS feed

  • Question

  • Is there a way to create WCF service OperationContract dynamically when the ServiceHost is invoked?  The specification of the service contract may come from config file.  Any examples? Thanks.

    Thursday, January 17, 2013 1:35 PM

Answers

  • Hi,

    >>Would it be possible to specify all the select statement in a web.config and when a client invokes the service, the operation contract is built based on what is specified in the config file. 

    I afraid this cannot be done with config, the configuration files providing endpoint and service behavior data at the point of deployment. But OperationContractAttribute can be used to indicate that a method defines an operation that is part of a service contract in a WCF app, if you do not want the method to be a part of the service contract, you can remove the attribute from the above of the method.

    You can refer a document below to take a look at WCF configuration schema.

    http://msdn.microsoft.com/en-us/library/ms731734.aspx

    Hope this can help you.

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 21, 2013 7:59 AM
    Moderator

All replies

  • Do you mean specifically include or (not) include already written methods to be included in the operations and behaviours of the service?

    *If what I wrote is what you want you can do this by referencing the existing (or a basic version of your endpoint contract) then add a new 'OperationDescription', 'MessageDescription' & 'MessagePartDescription' & it's return type.

    The methods behaviour object would implement the IOperationBehaviour and method to invoke (include) could be done implementing IOperationInvoker.

    I'm sure one of those keywords will likely bring up an example somewhere on google (or bing).


    Hope that helps.
    • Edited by XinTW Thursday, January 17, 2013 6:29 PM
    Thursday, January 17, 2013 6:28 PM
  • Thank you for your reply.  All the operations I need are select statements from a SQL database (tables or views and I can have stored procedures mapped to these).  Would it be possible to specify all the select statement in a web.config and when a client invokes the service, the operation contract is built based on what is specified in the config file.  So if later on, more selects are needed, we just need to modify the config file to add new operations.

    Is a simple example  somewhere?

    Thanks.

    Friday, January 18, 2013 3:04 PM
  • Hi,

    >>Would it be possible to specify all the select statement in a web.config and when a client invokes the service, the operation contract is built based on what is specified in the config file. 

    I afraid this cannot be done with config, the configuration files providing endpoint and service behavior data at the point of deployment. But OperationContractAttribute can be used to indicate that a method defines an operation that is part of a service contract in a WCF app, if you do not want the method to be a part of the service contract, you can remove the attribute from the above of the method.

    You can refer a document below to take a look at WCF configuration schema.

    http://msdn.microsoft.com/en-us/library/ms731734.aspx

    Hope this can help you.

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 21, 2013 7:59 AM
    Moderator
  • Thank you for posting the WCF configuration schema.  That is a very good reference.
    Wednesday, January 23, 2013 2:01 PM